I'm currently using React with React Router and React Relay. Each of these has ways of updating/passing data. React with useState, React Router with it's pushState wrapper (location.state), and Relay with it's updater() method.
I'm unsure however which I should be using to handle a global state (if any at all). There is a particular ID that all pages of my app need that is not a session. Imagine a form with let's say 5 steps. Step 1 has no ID, Step 2 gets the ID on successful submit, and now on steps 3-5 it needs that ID to be rendered into a hidden input (as an example). Let's call it formId.
Currently, I'm passing it using React Router with location.state but it feels wrong. Instead I feel like I should have a way to get this formId once it's set. If formId is null send them to Step 1 and if it's not null let the current page/route load.
Of course, I could use window.formId but that seems to most wrong.
I ended up using React's Context API.
It looked something like this
Then in my router
Then I can get and set those values like this