Skip to content

[Bug] useStore.persist is undefined in React Native #1795

Answered by miikebar
miikebar asked this question in General
Discussion options

You must be logged in to vote

It looks like this is caused by the fact that if you don't provide the storage option when creating the store, then localStorage is used by default, which is undefined on React Native.

Here's a repro setting a dummy storage implementation: https://snack.expo.dev/@michal.bar/zustand-persist-undefined-custom-storage. Once a storage option has been set the useBearStore.persist is no longer undefined.

Should the whole persist object be undefined because of this? Maybe it's something worth mentioning in the docs? In my case I didn't set the storage directly as I needed to set it dynamically based on some conditions using setOptions.

Replies: 2 comments 12 replies

Comment options

You must be logged in to vote
12 replies
@miikebar
Comment options

@dbritto-dev
Comment options

@miikebar
Comment options

@dbritto-dev
Comment options

@miikebar
Comment options

Answer selected by miikebar
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants