How to intercept event of dev reload on React Native? - react-native

How can I intercept the reloading process on Android (Dev menu -> Reload)?
I want to clear some part of Redux store when is happend the action.

The question provides quite a little insight but seeing that some working is required on the redux store every time there is a reload, you can catch INIT action fired by Redux every time the store is initialised, IMO

Related

Fast Refresh in production mode - React Native

i am new to react native. i already build mobile apps which take configuration from ENV file. i use Config from react-native-config. but now i want to change value of some property in that Config file.
I managed to call hook and get data. let's say the data is "X" and i success to store "X" in "Config.name". but nothing change in my app. i had to do fast refresh in order to see the changing.
my question is, is it possible to do fast refresh in production mode? if not, how can i work around with this? i have to call hook in order to get the data first so i think it was the problem since i couldn't call hook when the app in prebuilt. so the app took value from ENV file instead of waiting from hook call.

how to store data in App even After User Logout and Close the App. in react native

Is it possible To store some data in App. Even after User logout it and close it from recent Apps.
if yes then How.
I heard About redux and redux persist. But I am not able to store data in app when I logout and close my app from recent app. So I dont know if I cant execute it properly.
is redux and redux persist really store data even after app logout and close from recent app ??
or is there another method or library for that..
I Build an app and used Expo.Sqlite as a data store.
I even build an ORM for it if you are interested I could post it here to.

After updating a react native app, trigger an action before app launch (clean persistent store in my case)

I modified some redux store (using redux-persist) logic in my app, and when a user update the app, at the first launch he get a crash because of inconsistency between the previous store and my new code. If the user relaunch the app everything is fine.
How can i detect that this is the first launch of an updated app version, clean the store and then render the app with new store initialization ?
I know how to clean the store, the part i struggle with is the way to know if the app just got updated and it's the very first launch. I don't want to clean at every launch.
Thanks in advance

How to start Redux in React Native

I am new to React Native and I want to add Redux to my project.
And I want to know if redux store values are saved when app is exited.
If it is not saved, how can I handle this problem?
In web development, we use cookie and local storage. Thanks in advance.
[Edit]
If I must use async storage, is there any easy way to approach this?
Redux state is usually emptied upon when an app is exited (not minimised).
What you should to instead is to use AsyncStorage to persist your access token, and get them from same storage when the app starts. You can do this in a didMount lifecycle, or any other means you may choose.
There is Ayncstorage for react native which is equivalent to localstorage in browser.
You can refer this
https://reactnative.dev/docs/asyncstorage
Or you can use redux-persist if you want to persist redux store when app exits which would otherwise get lost.
https://github.com/rt2zz/redux-persist

React-native redux navigation state reset after crash

We are using redux navigation and persisting redux state. However, sometimes when the user navigates to the page and an unexpected error occurs app crashes with a white screen. If the app is launched again it obviously crashes again because the same state is loaded. As the result app becomes unusable - the white screen crash straight after the app launches.
I guess it is fine to crash the app if there is a bug on one of the screens, but because of one buggy screen I don't want to make the entire app unusable for a user and it would be great to somehow reset a state and enable the user to keep using other functionality of the app.
Any ideas on how to achieve that?
I think the real question is: do you want to persist navigation state at all? Do you really want to load last visited screen on app launch rather than the first screen of the app? I've never seen an app that does this
Another question is how do you persist your navigation state in redux. It was only a pattern when using older versions of react-navigation (v1 and v2 if I recall correctly) but even then it wasn't the optimal pattern to keep navigation state in redux (redux integration of react-navigation v1), let alone persist it on restarts. Navigation is something that should start fresh every time user launches the app
Also read about state persistence in current version (v5 - https://reactnavigation.org/docs/state-persistence) usually there is no redux involved at all
About state persistence: usually you only persist long-living things like auth state, authorization tokens, user settings, but not some dynamic data that gets discarded often. For example, if you open some page and fetch data to display on that page, there is no reason to persist that data in AsyncStorage, because why would you? This data should be reloaded every time page opens instead of restored from persisted state. Redux-persist lets you whitelist or blacklist different parts of the state
To summarize:
1. figure out if you need to persist navigation state at all. If not, problem solved
2. if you do, try to setup redux-persist the way that it doesn't persist short-living error-prone data
3. figure out how navigation state is persisted (through redux or on it's own, see examples in the links I provided earlier)
4. integrate react-native-exception-handler, catch exceptions and reset persisted navigation state in case of a crash