useEffect working pretty well with primitives, but then I need it to run when array value changes, e.g. I have props.items, then I load items but some ids are different. I tried to use it like this:
useEffect(() => {
}, [...props.items.map((i) => i.id)])
but this solution throws error from react, saying dependency array must not change between calls. Anyone managed to find solid workaround for this situation? Thanks in advance.
[props.items]should work if you update the array correctly (i.e. create a new instance when you add,remove or change items). If you are not doing that then you should do it.useEffect(() => { }, [props.items])should be fine. Theprops.itemsdon't need to be an array as well. If the reference ofprops.itemschanges, the hook will be triggered.