Replies: 1 comment
-
Can anyone help me here please? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I want to use the isValid flag value obtained by setting the validationOnMount attribute to true.I need to use the latest value in componentDidMount but the this function always has value false. I did check in componentDidUpdate and the value comes as true when the errors object is empty. However, I can't rely on componentDidUpdate since it gets called multiple times and I need to setState of my class component only when Formik isValid changes
Kindly let me know which function can I use to set the isValid into my state without getting the "Maximum update depth exceeded" error. Please note it's a class component
Detailed description below:
<Formik
innerRef={this.customFormikRef}
validateOnMount={this.state.debtor.draftMode==true}
enableReinitialize
validationSchema={this.schema}
onSubmit={console.log}
initialValues={{
.....
}}
initialErrors={{
....
}}
initialTouched={{
....
}}
{({
handleSubmit,
handleChange,
handleBlur,
values,
touched,
isValid,
errors,
}) => (<Form .....>)}
Lifecycle methods:
As expected gets called only once but before the validateOnMount changes the isValid flag
componentDidMount(){ console.log('Mount Debtor Ref is '+this.customFormikRef.current.isValid) }
Populates isValid correctly but as expected gets called multiple times.Need to set state here only when the state changes. Can compare the prevState and the exsting state(this.state). But is this a good approach or is there any other lifecyle method which can be used
componentDidUpdate(prevProps, prevState){ console.log('Update Debtor Ref is ' + this.customFormikRef.current.isValid) }
Beta Was this translation helpful? Give feedback.
All reactions