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

205
Views
React clear session storage data when switching to another page

Let's say I run my react app and navigate to localhost:8080/pageA that has showHeader and showFooter set to false. And these are stored in a reducer in the session storage. When I navigate to localhost:8080/pageB (on whitch showHeader and showFooter should be set to true) it still renders with showHeader and showFooter set to false because the session storage data is not cleared and gets inherited form pageA. I'm wondering how to clear the session storage and redux data when switching to another page.

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

0

You probably need to add your codes for better description, but if you're looking to run a function when you're leaving a page(Component) you can use componentWillUnmount for class components and useEffect for functional components

componentWillUnmount :

    componentWillUnmount() {
        sessionStorage.clear();
        //run function that clears your redux store
    }

useEffect :

  useEffect(() => {
    return () => {
        sessionStorage.clear();
        //run function that clears your redux store    };
  }, []);
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!