How to stop fetching start api url after going back from route? React/React-query

53 views Asked by At

Problem: When I click pokemon details on next pages, after going back, app is fetching everytime first 12 pokemons.

I want after going back to stay on current page.

Link to code sanbox https://codesandbox.io/s/bitter-pine-57iwo?file=/src/components/Pokemon/PokemonList.js

1

There are 1 answers

0
wmattei On BEST ANSWER

If you want to keep your pagination state, i'd recommend use use a state management tool, such as Redux, Even React context can handle this one.

As you are using the prev/next url approach, i don't think it would be good to store this values on the queryParams from the list route.

So, yeah, go for state management.

https://github.com/reduxjs/redux-thunk https://reactjs.org/docs/context.html