I cant seem to access Context state or component state from inside a DOM callback in a functional React component. I discovered the problem trying dispatch a state update in response to a document keypress.
Minimal Code sandbox demonstrating the problem here. Its a very basic reducer/context context.Provider object wrapping a child/useContext component to access context state.
The child implements a timer and a keypress callback. It also increments a local counter set with setState().
To test open the console and see the timer incrementing both the context and local component counter. Press any key to observe the callback referencing the initial state passed to the context.Provider component and the initial value for setState();
State updates arent accessible from within the DOM component.
Im always grateful for any advice given.Thanks