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

284
Vistas
How to use either react router useParams() or window.localStorage()

In my scenario , the component should take a value either from the URL or from localStorage but when I attempt to get value from useParams() it throws this error:

Uncaught ReferenceError: useParams is not defined

My code is:

const { userId } = useParams() || props;
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

I think you didn't import useParams, in which case do so at the top of your file :

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

Then do :

let {userId} = useParmas();
if(!userId) userId = props.userId;

Because useParams return an object, an empty object like so {} if there isn't any parameter, but {} is not false, so by doing so useParams() || props, if there isn't an userId parameter in you your url, you will always get undefined.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Make sure that you have imported useParams. If you have imported it already, then try doing this.

let { userId } = useParams();
if(!userId) userId = props.userId;
about 4 years ago · Juan Pablo Isaza Denunciar

0

If you are using a class component, you must use withRouter() instead.

import { withRouter } from "react-router";


class Whatever extends Component {
  render() {
    const { userId } = this.props.match.params;
    return null;
  }
}
about 4 years ago · Juan Pablo Isaza 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