SyntaxFix
Write A Post
Hire A Developer
Questions
Using Functional Components and React Hooks
const [array,setArray] = useState([]);
Push value at the end:
setArray(oldArray => [...oldArray,newValue] );
Push value at the begging:
setArray(oldArray => [newValue,...oldArrays] );