Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

488
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda