I have an external function that changes a state inside a component thru ref
and ImperativeHandler
hook
const [state, setState] = useState(0);
// inside component
const testFunc = () => {
setState(1)
}
// outside of component
function *generator {
yield ...
yield testFunc()
// next yield should wait till state is updated, only then it can be executed
yield ...
}
but I can't figured out how to track that state has been chaged, since setState
hook has no callback option.
How can I track the moment when the state changed in the outside function such as my generator
example?