Skip to content Skip to sidebar Skip to footer

How To Use SetState Call Back To Update Value Prop Of TextInput

I am new in React and trying to build dynamic form. It seems to work fine. The problem is when i type the field values, they are shown in screen, but the value property of Textinpu

Solution 1:

EnterValue3 = (e) => {
    e.persist();

    let item = { };

    this.setState({ item: {...this.state.item, address: e.target.value });
}

Replace all your function with spread operator rather than directly assigning into the object.


Solution 2:

Try this and check

EnterValue1 = (e) => {
  e.persist();
  this.setState({
    item: {
      ...this.state.item,
      Email: e.target.value,
    }
  });
}

Note: Your whole code may help much to debug your issue


Solution 3:

Just in case for someone interested. This may not be the best solution. As this is my first project in react native.

Although i was not able to get the values prop using this.state, and they remained null. For my dynamic form, i made a function containing my Views/textinput with an index argument, provided by my map function(which iterates over an array that has length equal to number of forms added). I used onChageText method and in setState used a callback to save the typed values in an object with an id, that needs to be equivalent to the index of my dynamics mapped form. Using index of object of arrays, values=this.state.object[index],values, is saved in dynamic form.

It still did not populate the values prop, but it sure did maintain the typed content in the front end of the previous form when i add new form.


Post a Comment for "How To Use SetState Call Back To Update Value Prop Of TextInput"