-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What's the reason for limiting setting the initial value only once? #52
Comments
what's the use case? |
i think the biggest annoyance would be forcing people to use |
I have an edit form where the data is loaded through react-query which uses an stale-while-revalidate caching strategy. This means the form is populated with possibly outdated data, then the data is reloaded in the background while the form is already mounted and then some fields' initial value may be updated. |
BTW: could the "first" initial values be set using ( |
Hmm that's a reasonable case. I think I might have used |
do you think that equality check I added in the above code is necessary? |
Should the expected behavior for going from defined to undefined be that the value clears? It seems so, right? In that case the check would have to go |
I played around with removing So we would need another value as a "reset" signal, how about export function useFieldInitialValue<Value>(
fieldAtom: FieldAtom<Value>,
initialValue?: Value | typeof RESET,
options?: UseAtomOptions
): UseFieldInitialValue {
const field = useAtomValue(fieldAtom, options);
const store = useStore(options);
React.useEffect(() => {
if (initialValue === undefined) {
return;
}
if (!store.get(field.dirty)) {
store.set(field.value, initialValue);
}
store.set(field._initialValue, initialValue);
}, [store, field._initialValue, field.value, field.dirty, initialValue]);
} |
🎉 This issue has been resolved in version 3.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
@schiller-manuel I'm revisiting the hydration as the current hook fails to initialize the form when rendered on the server (Next.js)
https://github.com/form-atoms/field/blob/main/src/hooks/use-hydrate-field/useHydrateField.ts |
The docs say about
useFieldInitialValue
:But where does this limitation come from?
Why can't the initial value be updated as follows?
The text was updated successfully, but these errors were encountered: