I have an App
component, with navigation, rendering a sub-component - Main
- that renders the full data of the selected navigation item. Once the first selection (navigation item) is made the state returned by useReducer never updates to the currently selected navigation item.
Here is the link to the full CodeSandbox example I have created to illustrate the behavior I am running into on my project. https://codesandbox.io/s/react-usereducer-misunderstanding-8oqgyt?file=/src/Main.tsx
Here is the crux of the issue:
const [state, dispatch] = useReducer(reducer, data);
Once this state
is set, navigating to other options does not change the state value even though the data
value is different.