react use state append to state code example Example: usestate array push setTheArray([...theArray, newElement]);