changing state value react
const [a, b] = React.useState(['hi','world']);
const dup = [...a]; //won't work without spread operator
b(dup);
changing state value react
const [a, b] = React.useState(['hi','world']);
const dup = [...a]; //won't work without spread operator
b(dup);
how to update state.item[1] in state using setState? React
handleChange: function (e) {
// 1. Make a shallow copy of the items
let items = [...this.state.items];
// 2. Make a shallow copy of the item you want to mutate
let item = {...items[1]};
// 3. Replace the property you're intested in
item.name = 'newName';
// 4. Put it back into our array. N.B. we *are* mutating the array here, but that's why we made a copy first
items[1] = item;
// 5. Set the state to our new copy
this.setState({items});
},
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us