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

Dynamic polling interval #182

Closed
shuding opened this issue Dec 6, 2019 · 0 comments · Fixed by #207
Closed

Dynamic polling interval #182

shuding opened this issue Dec 6, 2019 · 0 comments · Fixed by #207
Labels
bug Something isn't working

Comments

@shuding
Copy link
Member

shuding commented Dec 6, 2019

When changing refreshInterval dynamically:

const [int, setInt] = useState(0)
const { data } = useSWR('/api', { refreshInterval: int })

return <>
  {data}
  <button onClick={() => setInt(int + 1000)}>update</button>
</>

Sometimes the received data will not be updated from the data source upon interval changes. Need to refine the interval change logic and remove refreshInterval from the useEffect deps, and use a ref for it.

Also we need a test to make sure it'll be stable in the future.

@shuding shuding added the bug Something isn't working label Dec 6, 2019
@promer94 promer94 mentioned this issue Dec 18, 2019
shuding pushed a commit that referenced this issue Dec 23, 2019
* Fix #182

* use only 2 useEffect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant