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

147
Views
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 answers
Answer question

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 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!