React native sync-storage vs AsyncStorage - react-native

I'm still fresh with React Native. Stumbled upon some projects that uses sync-storage and AsyncStorage. Is there any difference between these 2 storage packages, base on scenario?

I've never heard of the sync-storage package but after looking into it, I can see that it relies on the deprecated package for async storage. Anyone who has been using async storage recently in react-native will point you towards the most up to date library: #react-native-async-storage/async-storage.

Related

Mocking requests in Storybook React Native

I would like to be able to setup stories for my react native screens, which hooks into the API via react query hooks. I'm using the beta version of storybook react native (6.0.1-beta3).
https://storybook.js.org/addons/msw-storybook-addon, which is what I'd normally use in a react project, won't work because service workers don't exist in react native (if I'm understanding things correctly).
I have also tried installing https://storybook.js.org/addons/storybook-addon-mock/, but wasn't able to get it work (storybook failed with a runtime error when trying to register the plugin... likely a version mismatch).
I might just have to go with a container/dumb component approach for the screens, but that has it's own drawbacks because queries or mutations can be nested in components.
I'm using axios for what it's worth. I've also considered putting the axios instance in a provider so I could modify the instance per test.
Thanks

React Native Expo shows Async Storage warning

i'm using React Native expo, and it shows
[Warning: Async Storage has been extracted from react-native core and will be removed in a future release. It can now be installed and imported from '#react-native-community/async-storage' instead of 'react-native'. See https://github.com/react-native-community/react-native-async-storage].
i read this link and I understood that it's due to the fact that some dependencies are using old AsyncStorage, not the new one from community.
But I hardly found that any solution for Expo users. Is there any solution for Expo? Or if I have to manual change dependencies using the old AsyncStorage, how can i do it? Since I'm new to React Native, not really sure what to do..
In Expo you should always link the libraries that Expo includes in the App. So like mentioned in the docs here https://docs.expo.dev/versions/latest/sdk/async-storage/
expo install #react-native-async-storage/async-storage
is the correct import. If you are working with an old Expo-SDK this might be different, otherwise you should adapt your imports.
Now expo has migrated to use as well the community version as you can see here.
But if you get this warning definitely you have some dependency or more that still use the react-native-core version, if so please refer to the first answer to How to resolve using AsyncStorage (deprecated) warning? Using the community (correct) library:
if this is the case the best is as suggested in that answer is to
Your best course of action is to fork the repo and fix all instances of AsyncStorage to use the correct version, or open an issue.
This error occurs because firebase imports AsyncStorage from react native core and not the new library #react-native-async-storage/async-storage. I think firebase hasn't updated the by default import yet so you have to do it yourself.The way I fixed it was ;
Install react-native-async-storage: npm i #react-native-async-storage/async-storage
Go into the firebase index.js file that imports AsyncStorage from react native core: It is located at : 'node_modules/#firebase/auth/dist/rn'.
Create a variable that imports AsycnStorage from 'node-modules/#react-native-async-storage/async-storage' :
var AsyncStorage = require('../../../../#react-native-async-storage/async-storage');
Replace all uses of AsyncStorage in this file from react native core with new variable, i.e. replace "ReactNative__namespace.AsyncStorage" with "AsycnStorage",

Will this module work in expo or react native?

I am new to react native and expo.
This is the module i am looking at: https://github.com/leesiongchan/react-native-esc-pos
I want to build an app that can print using bluetooth thermal printer. I am not sure if i should build it using react native or expo. Please advise me.
Thank you.
Expo has its own limitations and there are even some bugs there too, Its good for quick development as the documentation suggests the same that it is good to get you started with development within minutes without much hustle. In my opinion, React Native CLI is most of the time the best option even if you are new to react native development. Because of the following reasons
You will learn a lot as you will get your hands dirty in core react native app development.
You won't have to deal with expo limitations
You won't have to be dependent on expo tools
Any Library which requires linking or contains native modules will not work with the expo.
The library you mentioned uses many native modules and usually these type of libraries are not supported and that is the reason why they've built their own APIs and Native Components you can read this,
the developer has not mentioned Expo support anywhere on the docs but still You can open an issue on GitHub and ask the developer if it supports EXPO platform or not, or maybe instead of asking you can try the library yourself and you will find out if its working or not,

In Expo v35 managed workflow, how to handle `Warning: Async Storage has been extracted from react-native core`?

I use expo SDK v35, and works on the managed workflow (one without eject).
In my project, I face warning whenever I use AsyncStorage as demonstrated by their doc.
This, however, results in following warning being emitted:
Warning: Async Storage has been extracted from react-native core and will be removed in a future release. It can now be installed and imported from '#react-native-community/async-storage' instead of 'react-native'. See https://github.com/react-native-community/react-native-async-storage
I tried to follow the instruction given by this warning, and tried to use #react-native-community/async-storage, but it did not succeed; it appears the library requires some linking, which is not available if you want to work inside the Expo's managed workflow.
Question
What is the proper way to handle AsyncStorage warning when working on expo's managed workflow?
Env
Expo 35.0.0
Recently I began developing a simple app using react native and the expo cli. However, on the react native docs, it seems that asyncStorage is getting deprecated. The solution would normally be to use the react community version but that is not compatible with expo.
https://github.com/react-native-community/async-storage/
There is currently no scope of linking libraries while using the managed workflow of expo. I've faced similiar issues , and was bound to migrate from expo to pure react native. And expo isnt meant for production as apps are slower. Better i would suggest you to migrate to pure React native . Async storage cant be used otherwise and if deprecated , you will be in a great problem in the future for your app.

Converting Existing React Native Projects to Expo

I'm considering building mobile apps in React Native using Expo and I noticed under FAQ that existing React Native projects can be converted to Expo.
What exactly are we converting? I really like staying as pure and clean as possible without too many abstraction layers in the middle which can obscure my ability to understand what's really happening for things to work in the app.
I'd appreciate a bit more clarification about what's really happening in the conversion process and what Expo is adding to the existing project.
This topic is covered in the Expo XDE readme.
However, we didn't get it working and decided to port our code into the default Expo app (Edit: after hitting a lot of issues porting our app to Expo, we decided to revert to vanilla RN).
There are at least a few required steps missing from the documentation:
Create exp.json file
Update React and React Native libraries to the versions required by Exponent
"react": "16.0.0-alpha.6",
"react-native": "https://github.com/expo/react-native/archive/sdk-16.0.0.tar.gz",
We summarized on our blog why we gave up on Expo in its current form.