-
Hey Team, We have a parent component that contains formRenderer. It also has some state values. If we need to pass these state values to formTemplate then we have to use arrow function to pass it. For example in our code, You have a state in parent that is setName on clicking change count we can increase count and it works but if we setName (i.e click change name) then our name gets changed but it also initialses our count state to 0. How do we prevent this state from getting re-initiated? Steps to reproduce:
https://codesandbox.io/s/data-driven-forms-example-forked-edzn46
Thank you for help |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hello, This happens because To solve this re-initialization, you can provide the component outside the form component and use context to share the value: https://codesandbox.io/s/data-driven-forms-example-forked-stdle1 |
Beta Was this translation helpful? Give feedback.
Hello,
This happens because
() => <FormTemplate name={name} />
is a component and on each re-render you re-initialize a new instance of it.To solve this re-initialization, you can provide the component outside the form component and use context to share the value: https://codesandbox.io/s/data-driven-forms-example-forked-stdle1