Answers for "save object in state hook react"

2

prevstate in usestate

const [prevState, setState] = React.useState([]);

setState(prevState => [...prevState, 'somedata'] );
Posted by: Guest on June-09-2020
2

update state in useState hook

// declare state using useState hook.
// someState is set to someInitialState
const [someState, setSomeState] = useState(someInitialState);

// setSomeState updates the current state 
setSomeState(someOtherState);
Posted by: Guest on August-21-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language