Home > database >  How not to refetch data on revisiting the visited page on react?
How not to refetch data on revisiting the visited page on react?

Time:01-30

Suppose I have two routes /dashboard and /profile. Now I first visit /dashboard , data is fetched and shown on the page . Then I goto /profile page again data is fetched and displayed . Now when i go back to /dashboard page I dont want to fetch data again. How can I implement this in react? Any help will be great .

CodePudding user response:

  1. You can create your own cache mechanism using redux or context api,
  2. you can use react-query, it has inbuilt advanced caching option to fetch data
  •  Tags:  
  • Related