Can I use state = AsyncData(state.value!.copyWith(newState)); to update state? #3474
Answered
by
idispatch75
phamquoctrongnta
asked this question in
Q&A
-
Is it safe when I use below code to update state?
|
Beta Was this translation helpful? Give feedback.
Answered by
idispatch75
Apr 7, 2024
Replies: 1 comment
-
What may not be safe? |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
phamquoctrongnta
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What may not be safe?
If your concern is that
state.value
may be null, you can just usestate
methods to test that and update your state accordingly.If you use this code in response to user interaction, then you know whether this interaction is possible only when the state is loaded, and in this case you can just use
state.requireValue
(this avoid the !).Also inspect the API of AsyncValue, there are many interesting methods in there.