reset atoms if Provider initialValues changes #1462
-
I'm using a Provider to initialize an atom value (userAtom), where the initial value (user) comes from a async call up in the component tree. <Provider
initialValues={[
[userAtom, user]
]}
<Component />
</Provider> In this case the userAtom gets its value from user on the very first render, so as the user is yet being fetched, it will get a default value, like null, undefined, and not the desired value after user loads. From formik docs:
The output could be something like this: <Provider
enableReinitialize //Name taken from formik
initialValues={[
[userAtom, user]
]}
<Component />
</Provider>
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
In this use case, our current suggestion is to remount the Provider component. <Provider
initialValues={[[userAtom, user]]}
key={user.id}
> Hope it works. |
Beta Was this translation helpful? Give feedback.
In this use case, our current suggestion is to remount the Provider component.
Hope it works.