score:0
If you are using useFormik (formik hooks),
add the enableReinitialze prop on to the configuration object.
import React from 'react';
import { useFormik } from 'formik';
const SignupForm = ({ newInitValues }) => {
const formik = useFormik({
initialValues: newInitValues || {
firstName: '',
lastName: '',
email: '',
},
onSubmit: values => {
alert(JSON.stringify(values, null, 2));
},
enableReinitialze: true,
});
return (
<form onSubmit={formik.handleSubmit}>
<label htmlFor="firstName">First Name</label>
<input
id="firstName"
name="firstName"
type="text"
onChange={formik.handleChange}
value={formik.values.firstName}
/>
<label htmlFor="lastName">Last Name</label>
<input
id="lastName"
name="lastName"
type="text"
onChange={formik.handleChange}
value={formik.values.lastName}
/>
<label htmlFor="email">Email Address</label>
<input
id="email"
name="email"
type="email"
onChange={formik.handleChange}
value={formik.values.email}
/>
<button type="submit">Submit</button>
</form>
);
};
score:1
According to official github issue
from Formik
you should add enableReinitialize
prop: https://github.com/formium/formik/issues/811#issuecomment-410813925
score:32
You should set the enableReinitialize
prop.
<Formik
initialValues={{ email: context.email, username: context.username }}
enableReinitialize
Source: stackoverflow.com
Related Query
- How do you update Formik initial values with the react context api values after an AJAX request?
- How should the new context api work with React Native navigator?
- Formik - Update initial values after API call
- Unable to set props values after delete the record from the list in React context API
- how to populate options for a react select by fetching values from an api to be visible when you click on the select box?
- How can I make react render the new state modifications after I have updated the state with hooks and context
- With React useState how do you access key values of an array returned from fetch API
- How to update the React State only after a return from API called is completed
- Passing a function with React Context API to child component nested deep in the tree to update state value
- How do you can I update api result with the value of my input?
- How do I use the Contentful api data with React Context API (useContext in particular)?
- How to set the initial state value after fetching data to update a form in react
- React - How can I wait for the UI to update after multiple api calls?
- How to use context api with react router v4?
- How to pass state values to initial values in formik in react js
- Passing a function with React Context API to child component nested deep in the tree
- How to use React Hooks Context with multiple values for Providers
- How to get values from react FieldArray in formik form with other fields?
- After deploying a Github page, how do you update it with changes?
- What is the 'proper' way to update a react component after an interval with hooks?
- How to show an alert with errors found after submitting Formik form in react native
- How do I update the grapqhl cache with urql upon a mutation, where the initial query response does not include the required __typename?
- React (Native) Context API Causes Stack Navigator (React Navigation 5) to re-render after state update
- REACT - Set initial data in Formik Form after fetching from API
- How to use react context api with getDerivedStateFromProps?
- Getting SSR to work with the React Context API
- How to setup sublime 3 with react native so that when you click on the error and it jump to your code?
- How to retrieve the parameter after a hash (#) with React Router and useParams hook?
- How to declare the TypeScript types of a React Context initial state?
- Updating one of the Formik initial values with state resets all other values
More Query from same tag
- unsolved: change state with ant design select
- How can I get the daterange picker to return the value
- No overload matches this call. Overload 1 of 2 -- Yesterday same project worked
- How to fetch data from restAPI and from localStorage at a time?
- Webpack 4 code splitting not working with React.lazy
- Loading PDF from Base64 data using react-pdf-js
- Cannot upload image from React frontend to flask backend
- webpack:import global styles file into all components
- how can i add or update the property of an element of an array : Javascript
- React useState and useEffect nesting. Is this okay?
- Module Federation (Unexpected token '!==' main.js:619)
- Setting type for React Typescript component attribute
- How to change State from inside .Map function React
- Polling not working in React JS mixin
- What's Relay operation name?
- How to load react/react-dom in a single html page?
- Setstate of specific object in array
- Why doesn't React component doesn't render even though webpack doesn't throw any errors?
- Move between nested switches in react router v4
- What in React should actually be rendered
- React onClick JSX returned from function
- Render a react component n times
- Redirect to another component by clicking a button which is a part of existing component
- How to set elements xy-position relative to selected text in another element?
- Error: Unable to locate env file at default locations (./.env,./.env.js,./.env.json)
- Optimizing React-Redux connected PureComponent
- How to fix TypeError is not a function (testing promises with Jest)
- react-native android error Failed to install the app native_modules.gradle' line: 170
- JS: func is not a function (onClick)
- unable to move text up in react css component