-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
asyncStoragePersistor for React Native #2360
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
asyncStoragePersistor for React Native #2360
Conversation
|
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/tannerlinsley/react-query/A3EyaNQsLHX5dPi8hA8NDXxqSaCX |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 279faaa:
|
TkDodo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, but could you please streamline it with the other plugins, meaning:
- typescript
- add to tsconfig.types.json
- docs for the plugins
- package.json
- add it to the rollup config
basically, if you search for createLocalStoragePersistor-experimental everywhere, you'll see what you'll need to add :)
Added docs for plugins. Sorry, I am not a type script person and.. not very familiar with all the rollup config... :( |
|
no worries. I think I can check out the branch and add some commits I guess? |
|
Please feel free to add more commits. I can verify that the code is working coz I am running the codes now and tested a few times by restarting the app and can confirm querycache data is there. |
|
@TkDodo @Aung-Myint-Thein We are going to test this PR as well in the coming days. We'll keep you updated if we have any issues or comments. |
|
can you please update your fork and branch with the latest release, as we've now made some changes to the webstorageplugin and I would like to avoid conflicts |
|
|
||
| export const asyncStoragePersistor = ({asyncStorageKey, throttleTime}) => { | ||
| return { | ||
| persistClient: throttle(function (persistedClient) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether we should use throttle here because setItem is async so probably we want to return this promise as well :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
build fails because:
How are we going to go about this please? I'd rather not add this as a |
|
@TkDodo What about async |
Yes, we'd need something as a parameter that has an async |
tried that here: 0612612 |
I think so :D |
|
@TkDodo we could use smth like |
what would be the drawback of just using the normal throttle that doesn't return anything? |
|
@TkDodo Probably, there we could run into some race conditions. I mean one operation could be faster than the other one but the order is not maintained on JS side, but on the otherhand |
|
I came up with this https://gist.github.com/TMaszko/a6b9cb876340569c7daf8d520509d3c0 |
|
This is all looking really good. I think the changes to make things more flexible is the right move. Inverting control out of the API to the user is always a good decision, same way we did it with the other web storage api's. Keep cruisin'! |
dismissing because I implemented lots of it myself :)
|
I created a third-party module for this exact purpose a while ago: https://github.com/dan-lee/react-query-native-persist It can handle multiple storage backends (with the help of adapters). Maybe this can serve as inspiration regarding @tannerlinsley's point in his last comment. I'd also be willing to contribute if wanted. |
|
@TMaszko @Aung-Myint-Thein the PR would be good to go from my side, but I haven't really tested it. If someone can make a quick test with AsyncStorage, and maybe as well with localForage to see if it's compatible with the api, that would be much appreciated |
|
@TkDodo I've already tested AsyncStorage persistor in the project but in the form of custom persistor (gist code) and It was working correctly. |
Co-authored-by: Tomasz Krzyżowski <t.krzyzowski96@gmail.com>
|
When will it be merged? |
|
🎉 This PR is included in version 3.18.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Implementation
I looked at the createLocalStoragePersistor and just changed a few lines and necessary imports. Please feel free to suggest if there is anything I should change or improve.
How to use
How to test
Use some queries to get the data. Restart the React Native app. We should see the UIs with previously called queries immediately without needing to call the APIs.