0

in my react.js project I am using Ant design and I need to fill in my form in modal with values from state when the form is showed. Consider the following code sandbox: SANDBOX

Here we have modal with title field and value of title stored in state:

formfields:{
  title: "Some Title Here"
}

So when the form is showed I need the title field filled with Some Title Here. The main problem is that I dont want to place value of <Input> as this.state.formfields.title, so I dont want the state to update on every keystroke. Actually I need only take the data from state when the form is showed and update the state only when the form is submitted. No state updates should occur when the user inputs data into form fields. I checked some kind of THIS and THIS but it did not seem to work (maybe because of modal, anyway I dont know whether it is correct to do this like that).

Any ideas would be welcome. Thank you.

Masha
  • 827
  • 1
  • 10
  • 30

1 Answers1

0

Maybe you should set the value as a state value and set the formfields.title one when the form is submitted. If I understood your problem correctly, I mean...

  • I need to show the form with already preloaded values from the state, ie when the button is clicked, the field title should be already filled with the value from the state. But the state should not update when user modifies prefilled value in the title field – Masha Jan 26 '20 at 14:31
  • I see, so you could do as I said but set the value of the input related state to the same as the component loads. Using a component cycle function or the useEffect hook – Joaopedrofn Jan 26 '20 at 15:40