how to create a dynamic statehook?

Try this way

constructor(props){
    super(props);
    this.state = {
      textInput : [],
      inputData : []
    }
  }

onTextChanged = (index, value) => {
    const inputData = [...this.state.inputData]; 
    inputData[index] = value;
}

const textInput = [...this.state.textInput];
    
list.map((item,index) =>{
  //control true. i need creat textinput
  if (control) {
  
    textInput.push(
    <TextInput
      value={this.state.inputData[index] || ''}
          placeholder={item.name}
          onChangeText={(text) => this.onTextChanged(index, text)} 
    />
    );
  }

});


 this.setState({ textInput });

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top