Skip to content

Commit f4b4e8d

Browse files
committed
chore: bump version
1 parent 847c348 commit f4b4e8d

File tree

2 files changed

+97
-22
lines changed

2 files changed

+97
-22
lines changed

example/App.js

+96-21
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,104 @@
1-
import {MMKVLoader, useMMKVStorage} from 'react-native-mmkv-storage';
2-
const storage = new MMKVLoader().withInstanceID('settings').initialize();
1+
import React, {useCallback} from 'react';
2+
import {
3+
SafeAreaView,
4+
StatusBar,
5+
StyleSheet,
6+
Text,
7+
TouchableOpacity,
8+
View,
9+
} from 'react-native';
10+
import MMKVStorage, {create} from 'react-native-mmkv-storage';
311

4-
storage.setString('key_1', 'value_1');
5-
storage.setInt('key_2', 2);
6-
storage.removeItem('key_2'); // let's say we no longer need this key
12+
const Button = ({title, onPress}) => {
13+
return (
14+
<TouchableOpacity style={styles.button} onPress={onPress}>
15+
<Text style={{color: 'white'}}>{title}</Text>
16+
</TouchableOpacity>
17+
);
18+
};
719

8-
export default function App() {
9-
const [reactive_key_1] = useMMKVStorage('key_1', storage);
10-
const [reactive_key_2] = useMMKVStorage('key_2', storage);
11-
const [reactive_key_3] = useMMKVStorage('key_3', storage); // this key doesn't exist
20+
const storage = new MMKVStorage.Loader().withEncryption().initialize();
21+
const useStorage = create(storage);
1222

13-
const key_1 = storage.getString('key_1');
14-
const key_2 = storage.getInt('key_2');
15-
const key_3 = storage.getString('key_3'); // this key doesn't exist
23+
const App = () => {
24+
const [user, setUser] = useStorage('user', 'robert');
25+
const [age, setAge] = useStorage('age', 24);
1626

17-
// issue #1 - why reactive_key_1 is becoming undefined?
18-
console.log(`key_1: ${key_1} - reactive_key_1: ${reactive_key_1}`); // key_1: value_1 - reactive_key_1: undefined
27+
const getUser = useCallback(() => {
28+
let users = ['andrew', 'robert', 'jack', 'alison'];
29+
let _user =
30+
users[
31+
users.indexOf(user) === users.length - 1 ? 0 : users.indexOf(user) + 1
32+
];
33+
return _user;
34+
}, [user]);
1935

20-
// issue #2 - why we have two different default values for same key?
21-
console.log(`key_2: ${key_2} - reactive_key_2: ${reactive_key_2}`); // key_2: null - reactive_key_2: undefined
36+
const buttons = [
37+
{
38+
title: 'setString',
39+
onPress: () => {
40+
storage.setString('user', getUser());
41+
},
42+
},
43+
{
44+
title: 'setUser',
45+
onPress: () => {
46+
setUser(getUser());
47+
},
48+
},
49+
{
50+
title: 'setAge',
51+
onPress: () => {
52+
setAge(age => {
53+
console.log(age);
54+
return age + 1;
55+
});
56+
},
57+
},
58+
];
2259

23-
// issue #2 - why we have two different default values for same key?
24-
console.log(`key_3: ${key_3} - reactive_key_3: ${reactive_key_3}`); // key_3: null - reactive_key_3: undefined
60+
return (
61+
<>
62+
<StatusBar barStyle="dark-content" />
63+
<SafeAreaView style={styles.container}>
64+
<View style={styles.header}>
65+
<Text style={styles.headerText}>
66+
I am {user} and I am {age} years old.
67+
</Text>
68+
</View>
2569

26-
storage.indexer.strings.getKeys().then(r => console.log('keys: ', r));
70+
{buttons.map(item => (
71+
<Button key={item.title} title={item.title} onPress={item.onPress} />
72+
))}
73+
</SafeAreaView>
74+
</>
75+
);
76+
};
2777

28-
return null;
29-
}
78+
export default App;
79+
80+
const styles = StyleSheet.create({
81+
container: {
82+
alignItems: 'center',
83+
flex: 1,
84+
backgroundColor: 'white',
85+
},
86+
header: {
87+
width: '100%',
88+
backgroundColor: '#f7f7f7',
89+
marginBottom: 20,
90+
justifyContent: 'center',
91+
alignItems: 'center',
92+
paddingVertical: 50,
93+
},
94+
button: {
95+
width: '95%',
96+
height: 50,
97+
backgroundColor: 'orange',
98+
justifyContent: 'center',
99+
alignItems: 'center',
100+
borderRadius: 10,
101+
marginBottom: 10,
102+
},
103+
headerText: {fontSize: 40, textAlign: 'center', color: 'black'},
104+
});

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-mmkv-storage",
3-
"version": "0.7.3",
3+
"version": "0.7.4",
44
"description": "This library aims to provide a fast & reliable solution for you data storage needs in react-native apps. It uses [MMKV](https://github.com/Tencent/MMKV) by Tencent under the hood on Android and iOS both that is used by their WeChat app(more than 1 Billion users). Unlike other storage solutions for React Native, this library lets you store any kind of data type, in any number of database instances, with or without encryption in a very fast and efficient way.",
55
"main": "./dist/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)