I have a function that is supposed to set a piece of state to true
if a condition is truthy and show appropriate UI.
This sort of works but then it throws a no-op
error and flicks back to false immediately. I am also using a use effect to check on first render if the condition is truthy and show appropriate UI if so.
I am trying to use a teardown but am not familiar with them really. Any advice or pointers?
Error:
Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
Functions
const [isPatched, setIsPatched] = useState<boolean>(false);
useEffect(() => {
getApplied(x);
return () => {
setIsPatched(false);
};
}, []);
const getApplied = (x: any) => {
console.log(x);
if (x.Log) {
setIsPatched(true);
return;
} else {
setIsPatched(false);
}
};