Replies: 1 comment
-
This is exactly use case for smart stores. I am not sure about let user = atom<User>()
onMount(user, () => {
// load data from the cache store and request update from server if needed
() => {
// unbind all listeners
}
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm currently using Nano Stores to hold the current user in my React Native app and the current user's API token. I have listeners set up for each one that persist the store to AsyncStorage and SecureStore respectively.
Would it make sense to turn the user store into a computed store based off of the token? So whenever the token changes (i.e. app launch, login, and logout), new user data will be fetched from the server.
However, in the case of the app launching, I would like to display the (potentially stale) old data while the new data is being fetched.
Is this a use case for computed stores, or should I keep managing them separately? There will never be a case where there is a token but no user, or vice versa; I'm always updating them together.
Maybe I could add a listener to the token to update the user store?
Beta Was this translation helpful? Give feedback.
All reactions