I have an objectList and a size variable.
const [objectList, setObjectList] = useState([]); //will be filled elsewhere
const [size, setSize] = useState([props.width, props.height]); //might change on user input
useEffect(() => {
//When size changes iterate over objectList
objectList.forEach(object => {
object.set({
width: size.width,
height: size.height
);
});
}, [size]);
Here React complains, that objectList is not in dependency, because it might be, that I want to depend the useEffect on objectList changes. However I don't. Objects can be added to the list occasionally but in this case I am setting size where the object will be added to the list. I do not want to iterate over every object when I add a new object to the list (objectList changed), only when the size changed.
How can I iterate over the objectList on each size change but not on objectList change?