- Forums
- react
- React GET URL Params Value From URL Parameter Address Bar
This Page Contains information about React GET URL Params Value From URL Parameter Address Bar By jj in category react with 0 Replies. [5137], Last Updated: Mon Jun 24, 2024
jj
Tue May 30, 2023
0 Comments
267 Visits
To get the $_GET params from the URL in a React Application use the following code:
Import the useParams Hook:
import { useParams } from 'react-router';
TYPESCRIPT: Declare variable form the param value:
const { name } = useParams<{ name: string; }>();
Another way. See explanation
const { name } = useParams() as any;
NOTE: Cannot be a type of number
To change it to a integer, you may use this code instead:
let { qtimer } = useParams() as any;
qtimer = parseInt(qtimer);
Another Option:
let { qlength } = useParams<{ qlength: string; }>();
let { qtimer } = useParams<{ qtimer: string; }>();
const qtimerInt = parseInt(qtimer);
const qlengthInt = parseInt(qlength);
Javascript:
let { name } = useParams();
Use it
<ExploreContainer name={name} />