Closed tiwac100 closed 4 years ago
I got the same issue and after banging my head against the wall I did some deeper investigation on userSWR
.
Turns out initialData
is the initialData per fetch
, so you should only provide if your offset
is 0!
in my case i had to tweak to something like:
({ offset, withSWR }) => {
let initialData = null
if(!offset){
initialData = props.initialData
}
const { data } = withSWR(
// use the wrapper to wrap the *pagination API SWR*
useSWR(['myCustomEndpoint', offset || 0], fetch, {
refreshInterval: 0,
initialData
})
)
....
Once that part was figured out the rest just worked as smooth as you would expect!
I hope you have found the solution already ( :
@hems thank you so much!
@hems thank you so much!
de nada Matheus ( ;
@hems Perfect, thank you so much :)
@hems Perfect, thank you so much :)
thanks to the vercel guys, they rock ( :
The new pagination API has launched: https://swr.vercel.app/docs/pagination. Feel free to reopen if you are still encountering an issue!
I encounter the same issue with the new useSWRInfinite. If you provide initialData the when the other pages are fetched the data does not get updated.
When using
initialData
with Relay style cursor pagination theoffset
is null causing the same items to load again. AlsouseSWR
doesn't get rerun with the newoffset
but uses the cached result. A strange thing happens when resizing the window: previously loaded items now render correctly and are no longer all the same.The
items
prop (passed fromgetInitialProps
higher up the tree) has the same format as the data returned fromItemsGraphQLQuery
.