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

146
Vistas
react-route-dom v6 TypeError: Cannot read properties of undefined (reading 'state')

I am having trouble passing state to the component destination specified in Navigate.

    "react": "~18.1.0",
    "react-router-dom": "^6.3.0",

send ${address} valiable

  • from Wallet.js
    import { useNavigate } from "react-route-dom";

    const Wallet = ({ address, amount, symbol, destroy }) => {
        const navigate = useNavigate();
        return (
            <div>
                <button>
                    onClick={() =>
                    navigate("/booked", { state: { address: `${address}` } })
                    }
                </button>
            </div>
        );
    };
  • to RoomManagement.js
    import { useLocation } from "react-router-dom";

    const RoomManagement = () => {
        const { location } = useLocation();
        console.log("get address: ", location);
    }

But in console:

enter image description here

I tried to access, but it gives me an error.:

enter image description here

What would need to be modified?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

location is the object returned from the useLocation hook. state would then be destructured from location.

Examples:

const RoomManagement = () => {
  const location = useLocation();

  useEffect(() => {
    console.log("get address: ", location.state?.address);
  }, [location]);

  ...
}

or

const RoomManagement = () => {
  const { state } = useLocation();

  useEffect(() => {
    console.log("get address: ", state?.address);
  }, [state]);

  ...
}
about 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