I want to put the value of the state object 'nm', to the array 'Names[]' at a particular index 'uid'.Please check this code-
this.state={ Names:[], nm:'', status:false, uid:'' } upddata=(e)=>{ ** this.state.Names[this.state.uid]=this.state.nm; **`THIS LINE WORKS EXACTLY to put the updated data in array but shows warning: Do not mutate state directly. Use setState()` this.setState({ status:false, Names:this.state.Names, }) this.setState({nm:''}); }
The above code is working as expected and updates the data at particular index but it is giving warning. How can do that using this.setState??
I want to do this instead to avoid this warning: Do not mutate state directly. Use setState()