Skip to content

What is the use-case for synchronous fetcher? #917

Answered by huozhi
koba04 asked this question in General
Discussion options

You must be logged in to vote

In my understanding, swr can be used as a state managment library for various cases, not only for handling network requests. The revalidate action could mean "retrieve state from data source", which can be either sync or async.

Imagine we're building a todo list app, swr hooks can still be a great helper to access and cache states of todo items.

// getTodoItems can be a function reading todos from local states
const {data:todoItems} = useSWR('todos', getTodoItems)

here's another example in swr codebase https://github.com/vercel/swr/tree/master/examples/storage-tab-sync

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@koba04
Comment options

koba04 Jan 20, 2021
Collaborator Author

Answer selected by koba04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants