Potential race condition with deferFn run functions.
rstire364 opened this issue · comments
Demonstration: https://stackblitz.com/edit/react-2rszhm?file=src/App.js
We make use of context a great deal in our applications. Our intent was to use the deferFn, provide the entire state, and call the provided run function as necessary. This is working flawlessly when the run is called by a user action like a button press. However when programmatically calling the run function, like in a componentDidMount or useEffect(() => {}, []) the counter is incremented twice, the network request is fired, but the state never updates.
My assumption is theres a bit of race condition related to the counter initialization and the handleResolve call.
Yes, it also works when using the promiseFn, but this call is conditional. I'm certain we can rearchitect the DOM structure to circumvent this issue, but thought I'd bring it up.
Thanks for the package, big fans.