2

I am using React Native (version 0.46) to develop an app which does a few fetches data from a few resources, renders it and stores the data for display when internet connection is unavailable.

My question: I'm trying to see if its better to apply the "new" plan mentioned below instead of the current. Since RN is using JavaScript Core, is it running the code in a non blocking way like Node.js? advice is appreciated.

Current:
1. The app loads.
2. Check for internet connection (Asynchronously ofcourse).
3. If there is a connection: First, render cached data(if it exists), and second fetch for new data. If there is internet connection but no cached data, just fetch new data.
4. If there is no internet connection, fetch new data, render and store it.

New: Rather than waiting for internet availability, im simply going to render the cached data if available. Would this be a better approach? or is there a better one ?

4

1 回答 1

0

1. 将 redux-persist 添加到应用程序中。

2.将所有需要持久化的状态键加入白名单。

3. 有网络就进行api调用,成功则刷新状态

注意:我不得不延迟渲染(在 redux-persist 的 v4 中),直到存储重新水化,这在较新的版本中可能不需要。

https://github.com/rt2zz/redux-persist

另一种解决方案可能是 redux-offline 模块:

https://github.com/jevakallio/redux-offline

于 2017-08-10T07:34:57.647 回答