quarrant / mobx-persist-store

Persist and rehydrate observable properties in mobx store.
270 stars 14 forks source link

[Bug] React Native - ReferenceError: Storage is not defined #50

Closed sharon-laguna closed 3 years ago

sharon-laguna commented 3 years ago

Hi, In v1.0.1 I'm getting an unhandled exception when trying to use makePersistable. It seems like there's a missing import for Storage in isStorageControllerLike ?

Possible Unhandled Promise Rejection (id: 0): ReferenceError: Storage is not defined ReferenceError: Storage is not defined at Object.exports.isStorageControllerLike

codeBelt commented 3 years ago

I don't see that issue myself. Can you recreate it in https://codesandbox.io/ and paste the example here.

sharon-laguna commented 3 years ago

Hey, thanks for the quick reply and for working on this package! I can't recreate it in codesandbox as I'm trying to create a PoC with React Native. If you look at utils.ts, it seems that the recently added check for Storage is missing an import.

https://github.com/quarrant/mobx-persist-store/blob/e756ba326aab616fa8923eb56dd36cb4262b9467/src/utils.ts#L36

codeBelt commented 3 years ago

I will look into this. I haven't used this package in React Native. Storage is native to JavaScript but might not be supported in React Native.

@quarrant do you have experience in React Native and want to look at this also with me?

sharon-laguna commented 3 years ago

@codeBelt Checking if Storage is available seems to behave as expected in RN. const isStorageAvailable = typeof Storage !== 'undefined'; ... if (isStorageAvailable && value instanceof Storage) {...}