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

Add example sharing local state between components #76

Merged
merged 2 commits into from Nov 9, 2019

Conversation


export default () => (
<div style={{ padding: 40 }}>
useSWR can share state bettween components:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
useSWR can share state bettween components:
useSWR can share state between components:

@afc163
Copy link
Contributor Author

afc163 commented Nov 6, 2019

fixed

@shuding
Copy link
Member

shuding commented Nov 6, 2019

Thanks!

This is an interesting use case which uses SWR for global state management (like Redux). But currently SWR revalidates itself constantly (e.g.: on focus / new component being added, etc.) and will be set to initialStore.

I think we can add an option to support this use case better (turn off revalidation completely).

@shuding shuding added the discussion Discussion around current or proposed behavior label Nov 6, 2019
@afc163
Copy link
Contributor Author

afc163 commented Nov 6, 2019

Yeah, it is a tricky usage and I am happy to show potential of swr in multiple ways.

@shuding
Copy link
Member

shuding commented Nov 6, 2019

Although it can be supported with a latestState object like this: https://github.com/zeit/swr#subscription-eg-socketio

@afc163
Copy link
Contributor Author

afc163 commented Nov 8, 2019

Any chance to merge this?

@shuding
Copy link
Member

shuding commented Nov 9, 2019

@afc163 can you delete yarn.lock? And I’ll merge it. 👍

Although we’ll keep improving the example in the future.

Copy link
Member

@shuding shuding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Successfully merging this pull request may close these issues.

None yet

3 participants