swr icon indicating copy to clipboard operation
swr copied to clipboard

In react native, how to use cache to initialize provider?

Open blackhu0804 opened this issue 2 years ago • 1 comments

Bug report

Description / Observed Behavior

I want to achieve the same effect on the web. But my method of getting localstorage is asynchronous. How can I achieve this effect please?

Expected Behavior

https://swr.vercel.app/docs/advanced/cache#localstorage-based-persistent-cache

Repro Steps / Code Example

Additional Context

1.3.0

blackhu0804 avatar Jun 13 '22 03:06 blackhu0804

You could use MMKV if you're willing to install a native library. That uses sync storage persistence with better performance than AsyncStorage. It also works on Web (I added this).

https://github.com/mrousavy/react-native-mmkv

nandorojo avatar Jun 19 '22 18:06 nandorojo

In my library swr-idb-cache:

  1. Cache provider loads cached data asynchronously
  2. After it's ready, the <SWRConfig value={{ provider }} /> is created

piotr-cz avatar Oct 19 '22 18:10 piotr-cz