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

245
Views
unable to define navigate = useNavigate()

I'm trying to run this code:

  const navigate = useNavigate()
  <div>
    <button onClick={() => navigate("/")}>CLICK</button>
    <h1>HATS PAGE</h1>
  </div>
);

but somehow const navigate = useNavigate() gives me Parsing error: Unexpected token

Could anyone please help me with this problem?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can't put your statements which define variables in the middle of a JSX expression.

Define your variables first. Then do your JSX.

const navigate = useNavigate();

return (
    <div>
        <button onClick={() => navigate("/")}>CLICK</button>
        <h1>HATS PAGE</h1>
    </div>
);
about 4 years ago · Juan Pablo Isaza Report

0

Hooks need to be called at the top level of your React functional component.

function ComponentName() {
  const navigate = useNavigate();

  return (
    <div>
    <button onClick={() => navigate("/")}>CLICK</button>
      <h1>HATS PAGE</h1>
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza 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!