I have a react component and want a specific part of its state to update to true when a condition is truthy:
I am trying to use useEffect() to achieve this.
const [isPatched, setIsPatched] = useState(false);
useEffect(() => {
x.log ? setPatched(true) : setPatched(false);
}, [x.log]);
const setPatched = (patched: boolean) => {
console.log(patched); //logs out true
setIsPatched(patched);
console.log(isPatched); //logs out false
};
I can't figure out why isPatched
is remaining false
despite the function setting it to true
.