I have a useEffect that I want only to be run on the initial render and when a variable changes. That means that I don't want it to be run every time the component rerenders. This is where I'm stuck, this is my current code simplified:
useEffect(() => {
// Some logic only to be performed when variable changes OR at initial render
}, [variable]);
Any ideas on how to achieve this?
{ isVisible && <YourComponent /> }... & isVisible is changing, i dont think you can prevent this at a hooks level, unless you do some sort of global memoization outside the component