I am trying to delete items from state variable in useEffect using the props comming to the component. I want to take initial values from state variable and then delete elements in that array and set the state variable again to new value. But When I don't pass the state variable in dependency array it is throwing warning as React Hook useEffect has a missing dependency: 'abc'. Either include it or remove the dependency array
and when I pass it, It goes in infinite loop which I think is correct because of useeffect working. This is the useffect I am trying:
const [abc, setAbc] = useState([]);
useEffect(() => {
axios.get(url).then(res => setAbc(res));
}, [props.bbb])
useEffect(() => {
if(props.xyz) {
let aaa = abc.filter(key => key.id === props.xyz);
setAbc(aaa);
}
}, [props.xyz])
Is there something I am missing here? Is there any better way to do this?
Thanks in advance.