I have a simple code here. I am using react-router and I can't get why the state of all pages are fixed to the one of the initial render and the inputfields share all the value?
import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";
import Page from "./Page";
export default function App() {
return (
<Router>
<Link to="/">Home</Link>
<Link to="/about">About</Link>
<Link to="/users">Users</Link>
<Switch>
<Route path="/about">
<Page direction="left" />
</Route>
<Route path="/users">
<Page direction="right" />
</Route>
<Route path="/">
<Page direction="up" />
</Route>
</Switch>
</Router>
);
}
import React, { useReducer } from "react";
export default function Page({direction}){
let reducer = (state, action) => state;
let [state, dispatch] = useReducer(reducer, {direction});
return (<div><input type="text"/>{state.direction}</div>)
}