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

Any way to communicate request progress to swr? #159

Closed
ephys opened this issue Nov 28, 2019 · 2 comments
Closed

Any way to communicate request progress to swr? #159

ephys opened this issue Nov 28, 2019 · 2 comments
Labels
discussion Discussion around current or proposed behavior

Comments

@ephys
Copy link

ephys commented Nov 28, 2019

Hello :)

Is there any plans to let us pass the progression percentage of the current fetch operation to useSWR?

Maybe something like

useSWR(
	'/big-dataset',
	(emitProgress) => /* fetch & call emitProgress when new data is loaded */,
	{ trackProgress: true },
);

This would allow us to use determinate progress indicators :)

Thanks!

@shuding
Copy link
Member

shuding commented Dec 1, 2019

Why not handling that inside fetcher? 😄

const [progress, emitProgress] = useState(0)
useSWR('/big-dataset', url => fetch(url, emitProgress))

Or you can build your own abstraction around that (like a custom hook useSWRWithProgress).

I think one of the most important feature of SWR is tiny, but highly flexible (isolated from the actual fetch handler).

Related to #129.

@shuding shuding added the discussion Discussion around current or proposed behavior label Dec 1, 2019
@shuding shuding mentioned this issue Dec 1, 2019
@ephys
Copy link
Author

ephys commented Dec 3, 2019

That solution works for me, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Discussion around current or proposed behavior
Projects
None yet
Development

No branches or pull requests

3 participants