I'm using formik library in my react application. Initially, I declared state values in the constructor, In componentDidMount I'm calling an API with that app response am updating state values, Can anyone help me in passing state values to fomik initial values
In my situation formik taking initial state values which are declared in the constructor.thanks in advance
class Dropdown extends Component {
constructor(props) {
super(props);
this.state = {
//some data
};
}
componentDidMount() {
//api call
this.setState( {
//update state values with api response data
});
}
render() {
return (
<Formik
initialValues={this.state}
validate={validate(validationSchema)}
onSubmit={onSubmit}
render={
({
values,
errors,
touched,
status,
dirty,
handleChange,
handleBlur,
handleSubmit,
isSubmitting,
isValid,
handleReset,
setTouched
}) => (
//form uses initialValues
)} />
)
}
}