Skip to content

Commit 71234c3

Browse files
authored
Merge branch 'master' into develop
2 parents 61238c6 + b8a17e9 commit 71234c3

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

example/App.tsx

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import React, {useEffect, useState} from 'react';
2+
import {
3+
SafeAreaView,
4+
StyleSheet,
5+
ScrollView,
6+
Text,
7+
StatusBar,
8+
} from 'react-native';
9+
import MMKV from 'react-native-mmkv-storage';
10+
11+
const MMKVStorage = new MMKV.Loader().withEncryption().initialize();
12+
13+
interface StoredMap {
14+
name: string;
15+
date: number;
16+
}
17+
18+
const App = () => {
19+
const [stringValue, setStringValue] = useState('');
20+
const [arrayValue, setArrayValue] = useState<Array<undefined>>([]);
21+
const [mapValue, setMapValue] = useState<StoredMap>({
22+
name: '',
23+
date: Date.now(),
24+
});
25+
26+
useEffect(() => {
27+
const map = MMKVStorage.getMap<StoredMap>('map');
28+
map && setMapValue(map);
29+
MMKVStorage.removeItem('map');
30+
MMKVStorage.setMap('map', {
31+
name: 'AAA',
32+
date: Date.now(),
33+
});
34+
const randomString = MMKVStorage.getString('random-string');
35+
randomString && setStringValue(randomString);
36+
MMKVStorage.setString(
37+
'random-string',
38+
Math.random().toString(36).substring(7),
39+
);
40+
const array = MMKVStorage.getArray<undefined>('array');
41+
array && setArrayValue(array);
42+
MMKVStorage.setArray('array', new Array(16).fill(undefined));
43+
}, []);
44+
45+
return (
46+
<>
47+
<StatusBar barStyle="dark-content" />
48+
<SafeAreaView>
49+
<ScrollView
50+
contentInsetAdjustmentBehavior="automatic"
51+
style={styles.scrollView}>
52+
<Text>Previous value: {stringValue}</Text>
53+
<Text>
54+
Map value: {mapValue?.name} {mapValue?.date}
55+
</Text>
56+
<Text>Array Length: {arrayValue?.length}</Text>
57+
</ScrollView>
58+
</SafeAreaView>
59+
</>
60+
);
61+
};
62+
63+
const styles = StyleSheet.create({
64+
scrollView: {
65+
padding: 32,
66+
},
67+
});
68+
69+
export default App;

example/tsconfig.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"compilerOptions": {
3+
"allowJs": true,
4+
"allowSyntheticDefaultImports": true,
5+
"esModuleInterop": true,
6+
"isolatedModules": true,
7+
"jsx": "react",
8+
"lib": [
9+
"es6"
10+
],
11+
"moduleResolution": "node",
12+
"noEmit": true,
13+
"strict": true,
14+
"target": "esnext",
15+
"paths": {
16+
"react-native-mmkv-storage": [
17+
"../index.d.ts"
18+
]
19+
}
20+
},
21+
"exclude": [
22+
"node_modules",
23+
"babel.config.js",
24+
"metro.config.js",
25+
"jest.config.js"
26+
]
27+
}

0 commit comments

Comments
 (0)