App.js file
export default function App() {
    return (
        <div className="h-100">
            <Routes>
             <Link to={
                {
                    pathname: "/posts",
                    state: {test: 'test'}
                }
                }>Posts</Link>
                <Route path="/" element={<Home/>}/>
                <Route path="/login" element={<Login/>}/>
                <Route path="/posts" element={<Posts/>}/>
            </Routes>
        </div>
    )
}
expected to pass state,some piece of data from one page to another when using useLocation to get state from another page state is null
index.js file
import {BrowserRouter as Router} from "react-router-dom";
import App from "./App";
ReactDOM.render(
    <React.StrictMode>
        <Router>
            <App/>
        </Router>
    </React.StrictMode>
    ,
    document.getElementById('root')
);
Posts.js file
const location=useLocation()
console.log(location);
Output
Object { pathname: "/posts", search: "", hash: "", state: null, key: "hpuuzep5" }
package.json
{
  "name": "chance",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.9",
    "@testing-library/react": "^11.2.5",
    "@testing-library/user-event": "^12.6.3",
    "axios": "^0.21.1",
    "bootstrap": "^5.0.0-beta3",
    "history": "^5.0.0",
    "ramda": "^0.27.1",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-router": "^5.2.0",
    "react-router-dom": "^5.2.0",
    "react-scripts": "4.0.2",
    "styled-components": "^5.2.3",
    "web-vitals": "^1.1.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}
I can not either import switch from react-router-dom, it says switch is not exported from react router dom, I think have correctly set up my routes where is the error i can not pass state from one route to another