I want to get id in url i tried both ways but i get an error can anyone help about the solution?
Error :
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
You might have mismatching versions of React and the renderer (such as React DOM) You might be breaking the Rules of Hooks You might have more than one copy of React in the same app See
url: http://localhost:8080/passenger-update/16
Following my code:
class PassengerUpdate extends Component {
componentDidMount() {
let { id } = useParams();
console.log(id);
}
render() {
return (
<div className="container">
</div>
);
}
}
export default PassengerUpdate;
This Router Code
<Routes>
<Route exact path="/passenger-update/:id" element={<PassengerUpdate/>}/>
</Routes>
package.json
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production"
},
"devDependencies": {
"@babel/preset-react": "^7.13.13",
"@popperjs/core": "^2.10.2",
"axios": "^0.25.0",
"bootstrap": "^5.1.3",
"laravel-mix": "^6.0.6",
"lodash": "^4.17.19",
"postcss": "^8.1.14",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"resolve-url-loader": "^5.0.0",
"sass": "^1.32.11",
"sass-loader": "^11.0.1"
},
"dependencies": {
"react-bootstrap": "^2.4.0",
"react-router-dom": "^6.3.0"
}
}