I have a functional component react version is 17
export default function Comp(props){
.
.
.
useEffect(() => {
return () => {// cleanup
console.log("Called!")
}
}, [...dependiences])
}
I have another button that mounts and unmounts the component
for some reason, the clean-up function is getting called on mounting the component
and I can see the console Log
How can I prevent this from happening and call the clean up only if the component is un-mounting
The parent creates the component like this
export default function Comp(props){
.
.
.
const [mount, setMount] = useState(false);
return <> {mount && <Child {...someProps}/>}</>
}