I have a useState array that is being set with an array received from the backend. I am creating a new array equal to it and using _.remove
to delete items from it. However, the original useState array is also having items deleted from it. I cannot figure out why this is the case
const [backendArray, setBackendArray] = useState([{some values}])
const newArray = backendArray;
useEffect(() => {
const arrayForPurpose1 = _.remove(newArray, function (n) {
return n.value != null;
}), [backendArray]};
Both arrayForPurpose1
and backendArray
have item.values equalling null
. Why is that the case? I created newArray
thinking that would sever connection between the _.remove
and backendArray
but it didn't.