useParams tp pass params from route to component

PHOTO EMBED

Thu Aug 11 2022 23:47:18 GMT+0000 (UTC)

Saved by @SamMrch #react

const App = () => {
  return(
    <Router>
      <Routes>
        <Route path="/component1" element={<Component1 />} />
		<Route path="/component2/:data" element={<Component2 />} />
      </Routes>
    </Router>
  )
}
const Component2 = () => {
  const { data } = useParams();
  return(
    <div>
      <h2>The data is: {data}</h2>
    </div>
  )
}
content_copyCOPY