When hello
method is called second time, it should print console.log
but it is not. What iam missing here
function MyComponent() {
const [test, setTest] = useState(false);
useEffect(() => {
hello();
setTimeout(() => {
hello();
}, 2000)
}, [])
const hello = () => {
if(test == false) {
setTest(true);
} else {
console.log("Output:", test);
}
}
return(<h1>{test ? "Hai" : "Hello"}</h1>)
}
question from:https://stackoverflow.com/questions/65600833/react-component-state-is-not-persisting-between-method-calls