I use both 'react-native-mmkv' and 'redux' in my project, but there is no big difference in the way data is stored and used. Aside from the performance, what's better for storing and using data securely? Or is it better to use both methods?
I am sorry that I am not good at English.
is my code
import * as React from 'react';
import {
SafeAreaView,
Text,
Pressable,
} from 'react-native';
// UI components
import { Button } from 'atoms';
import { Card, SelectList } from 'molecules';
// Hooks
import { useIsFocused } from '@react-navigation/native';
// Redux
import { useAppSelector, useAppDispatch } from 'hooks';
// utils
import { initializeAccountData } from 'utils';
import { useMMKVString } from "react-native-mmkv";
const App = ({ navigation, route }: any) =\> {
// Navigation
const isFocused = useIsFocused();
// Redux
// const { accounts } = useAppSelector(state =\> state.accounts);
// const dispatch = useAppDispatch();
// MMKV Hooks
const \[accounts, setAccount\] = useMMKVString('accounts')
// Update to didMount, update
React.useEffect(() =\> {
const dataInitialize = async () =\> {
await initializeAccountData();
}
dataInitialize();
}, \[\]);
// Update to page focusing
React.useEffect(() =\> {
}, \[isFocused\]);
// Update to account change
React.useEffect(() =\> {
}, \[accounts\]);
return (
\<SafeAreaView style={{ flex: 1 }}\>
...
\</SafeAreaView\>
)
}
export default App;
CodePudding user response:
Redux is in memory storage, if you kill your app you will lose app state.
MMKV is persistent storage and you need to use it if you want to save data for the long term.
You can connect MMKV with redux if you want to store redux state. An example is here https://github.com/mrousavy/react-native-mmkv/blob/master/docs/WRAPPER_REDUX.md