Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Arguments lead to Infinite loop #113

Closed
beidan opened this issue Nov 12, 2019 · 2 comments
Closed

Multiple Arguments lead to Infinite loop #113

beidan opened this issue Nov 12, 2019 · 2 comments

Comments

@beidan
Copy link

beidan commented Nov 12, 2019

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

@shuding
Copy link
Member

shuding commented Nov 12, 2019

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

Like I said here #112 (comment), 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 }))

@shuding shuding closed this as completed Nov 12, 2019
@beidan
Copy link
Author

beidan commented Nov 12, 2019

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

thanks ~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants