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

214
Views
React Navigation RangeError: Maximum call stack size exceeded (native stack depth)

So I have a screen where I want the user to stay. If he want's to leave I want him to go to a specific screen. If I do it like this:

  useEffect(() => {
    navigation.addListener("beforeRemove", (e) => {
      e.preventDefault()
      navigation.popToTop()
    })
  }, [navigation])

I get this error: RangeError: Maximum call stack size exceeded (native stack depth)

Even if I change navigation.popToTop() to something else (e.g. navigation.navigate("Account")) I'll get the same error :/

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

0

The final array in your code is the useEffect "dependencies array", meaning the useEffect will run whenever anything in that array changes. Adding the listener to the navigation object changes the object, so you're either adding an infinite number of listeners, or replacing the existing one in a loop (I'm not sure how navigation.addListener is implemented).

You need to do one of the following:

  • check that the listener exists in this code block and only add if it doesn't
  • make sure this adding code only executes once
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!