I have a reactjs app, where I have a context wrapping my routes, that has multiple useStates and one is a values: string[] and a setValues: (v: string[]) => void function that calls the useState and writes to localstorage.
On the page I call a function that received this context and calls the setValues and pushes a new route (using react-router-dom V5.0.0) and on that differente route, I use the values again from that context.
I’ve noticed that sometimes (not consistently) the values does not include the added item on the pushed route after calling the function.
Is this to be expected? If not, do I need to introduce a useEffect to check if the context value has been updated, and only then push the new route? This does not seem to fall into the external syncronization that the react docs refer to for using useEffect…
I can provide code if it wasn’t clear.
Thanks
I’ve tried using useEffect to wait for the update but its so ugly, and feels wrong