I am trying to push an item to an array in the state but it is not working. Here is my code.
const [features, setFeatures] = useState(['']) const addFeature = (event)=>{ event.preventDefault(); let featuresClone = features; featuresClone.push(''); setFeatures(featuresClone); console.log(featuresClone, fetaures); } This is the function which updates the state. In the log here features is updated. but, when I do a useEffect like this,
useEffect(()=>{ console.log(features) },[features]) It will not log the features which means features is not updated.
What am I doing wrong?