Swr: Multiple Arguments lead to Infinite loop

Created on 12 Nov 2019  路  2Comments  路  Source: vercel/swr

in my code, when i pass one param it can success.
but when i pass Multiple Arguments , it Infinite loop.
image
image

Most helpful comment

maybe It's better to write it in a document
image

thanks ~

All 2 comments

SWR shallowly compares the arguments on every render, and triggers the validation if any of them has changed.

Like I said here https://github.com/zeit/swr/issues/112#issuecomment-552809810, don't pass { schoolCode } as an argument because {} !== {}. It works exactly like React Hook dependencies.

You can do either:

useSWR(['...', useMemo(() => ({ schoolCode }), [schoolCode])], fetcher)

or

useSWR(['...', schoolCode], (method, schoolCode) => fetcher(method, { schoolCode }))

maybe It's better to write it in a document
image

thanks ~

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bcomnes picture bcomnes  路  3Comments

bywo picture bywo  路  4Comments

alexanderbluhm picture alexanderbluhm  路  3Comments

zahraHaghi picture zahraHaghi  路  3Comments

dandrei picture dandrei  路  3Comments