Open dan-irf opened 11 months ago
Latest commit: ede339914e01a160d9aef10c2231deb4e5569a6d
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
formik-docs | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Dec 22, 2023 2:01pm |
This pull request is automatically built and testable in CodeSandbox.
To see build info of the built libraries, click here or the icon next to each commit SHA.
Latest deployment of this branch, based on commit ede339914e01a160d9aef10c2231deb4e5569a6d:
Sandbox | Source |
---|---|
Formik TypeScript Playground (forked) | Configuration |
@quantizor @johnrom @jaredpalmer just wanted to ask you for PR review explicitly
I'm not sure what the purpose of this change is. Are you creating a new status based on the last status? It's not really clear by default where this status comes from (render or state), so I would expect Formik (if it is being brought back from the dead) to move in a direction where the source of this value can be determined explicitly, either within a render using useFormikContext().status
, or the absolute current value which may be "ahead" of the render, using a getState()
-like API, similar to redux.
const { setStatus, getState, status } = useFormikContext();
useEffect(() => { setStatus(status === "value in current render" ? "a" : "b"); }, [setStatus, status]);
useEffect(() => { setStatus(getState().status === "absolutely current value" ? "a" : "b"); }, [setStatus, getState]);
You can see what that API could look like here: #3231 (the file doesn't load initially, so check Formik.tsx -> useFormik -> useFormikSubscription()
).
Problem
When setting status, sometimes user needs to update the existing value. When used inside a useCallback hook for instance, it introduces an unnecessary variable to the dependency list.
Solution
setStatus now acepts a patching function