Answers for "react useState setState append object"

14

usestate array push

setTheArray([...theArray, newElement]);
Posted by: Guest on June-02-2020
2

prevstate in usestate

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

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

Code answers related to "Javascript"

Browse Popular Code Answers by Language