i'm working on a react project and I have an object in array I have set the initial state to
input: [
{item:'', label :'', codeBlock:''}
],
on an onClick event, i set the state of the values of the elements in the javaSript object and push them into the input array with the code below
Text(){
const input = this.state.input;
const item = <input type="text" placeholder="Enter text here!"
className="InputDiv" onChange={this.handleTextChange.bind(this)}/>
const codeBlock = <input type="text" placeholder="Enter text here!"
className="InputDiv"/>;
const label = this.state.label;
this.setState({input : input.concat({item, label, codeBlock})});
console.log(this.state.input)
}
Now i am trying to update the value of the label element on an onChange event, handleTextChange. What i mean is for the current state, on an onChange event, set just the value of the label and update the state.
Please how will i do this in React?
Thanks
labelto update (since you have an array), which presumably you do have in your code. Please update your question with a minimal reproducible example demonstrating the problem, ideally a runnable one using Stack Snippets (the[<>]toolbar button). Stack Snippets support React, including JSX; here's how to do one.