State Driven View Management
State-Driven View Management
In the previous lesson, you set up a global store using useReducer and Context. That store gives us state and dispatch anywhere in the app. Today, you will use that setup to control which screen is visible — without React Router. This is a small but powerful pattern: the UI screen is just state (ui.screen), and navigation is just dispatching an action to change that state.
Rendering Screens From Global State (App root)
Explanation:
GameProviderwraps the app so all children can access state and dispatch (from the previous lesson’s store).AppContentreadsstate.ui.screenusinguseGameContextand picks which screen to render with a simple switch. No routing library is needed.- The
SafeXcomponents are fallbacks so the app can run even if a screen is missing. In your real project, you will have the actual components. - Changing
state.ui.screentriggers a re-render, which switches the visible screen.
