Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

490
Views
React Hooks - How to get parameter value from query string

How can I use react hooks and get query string value?

with react class I use : const id = this.props.match.params.id;

over 4 years ago · Santiago Trujillo
4 answers
Answer question

0

In React Hooks:

Suppose your URL is like this: http://localhost:3000/user?name=John&id=10

Then you can use useLocation hook to get your job done.

import React from 'react';
import { useLocation } from "react-router-dom";

function VerifySignup() {
    const search = useLocation().search;
    const name = new URLSearchParams(search).get('name');
    const id = new URLSearchParams(search).get('id');
    console.log({ name, id })
    return (
        <div>
            Verify Signup
        </div>
    )
}

export default VerifySignup

over 4 years ago · Santiago Trujillo Report

0

You can use useParams and set the id as a dependency of the effect:

const Component = () => {
  const { id } = useParams();
  useEffect(() => 'do something when id changes', [id]);
};
over 4 years ago · Santiago Trujillo Report

0

import { useParams } from "react-router-dom";

in component:

const { id } = useParams();

https://reacttraining.com/react-router/web/api/Hooks/useparams

over 4 years ago · Santiago Trujillo Report

0

here is another pure javascript way

assuming your URL = localhost:3000/example?id=123

  React.useEffect(() => {

    const params = new URLSearchParams(window.location.search) // id=123
    let id = params.get('id') // 123 

}, [])

you can also check if the query params exist or not by has like

params.has('id') // true
params.has('name') // false
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!