8000 Formik creates infinite renders when initial value changes · Issue #3639 · jaredpalmer/formik · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Formik creates infinite renders when initial value changes #3639
Open
@sukhijamahima

Description

@sukhijamahima

Bug report

Current Behavior

I am using formik in react js project. The form has first name input which takes initial values from local storage if available. On change of first name input, I change its value in local storage.
const prefilledValues = JSON.parse( window.localStorage.getItem("pre-signup-form") );

useEffect(() => { window.localStorage.setItem( "pre-signup-form", JSON.stringify({ ...prefilledValues, ...formik.values }) ); }, [formik.values, prefilledValues]);

I am using useFormik to set initial values. When I change the first name input, which basically changes the value in local storage and hence initial values, It causes too many renders and the page becomes unresponsive.

Expected behavior

Should not cause too infinite renders

Reproducible example

https://codesandbox.io/s/youthful-saha-63bp8t?file=/src/App.js

Your environment

Software Version(s)
Formik 2.2.9
React 18.2.0
TypeScript N/A
Browser Chrome Version 104.0.5112.101
npm/Yarn N/A
Operating System Mac Os@12.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0