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

171
Views
React Hook "useNavigate" is called in function

i am trying to create a token, when its expired ... redirect it to login page. but as soon as i add navigate('/login') i am getting an error Error-"React Hook "useNavigate" is called in function"

what am i doing wrong? how can i navigate to login page?

const me = async (token) => {
const navigate = useNavigate()
  let config = {
    headers: {
      Authorization: "Bearer " + token
    }};
    
  try {
    const response = await axios.get(API_URL + 'api/users/me', config)
  } catch (error) {
    logout()
    reset()
    // navigate('/login')
  }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

So useNavigate is a React Hook. As such, it cannot be called within a nested function.

You'll see an example of how to call useNavigate inside the top-level React function in that sandbox.

You may want to check out https://reactjs.org/docs/hooks-rules.html for more references.

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!