Skip to content

Commit 1e0550b

Browse files
committed
fix(rn-example): update to show errors
1 parent 02f1fe8 commit 1e0550b

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

examples/example-react-native/src/BasicCrud.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,22 @@ import { createAsyncStorage } from "@react-native-async-storage/async-storage";
1010
import React, { useState } from "react";
1111
import { Alert, Button, StyleSheet, Text, View } from "react-native";
1212

13-
function GetSet() {
13+
export const STORAGE_KEY = "random";
14+
15+
const BasicCrud: React.FC = () => {
1416
const [storedNumber, setStoredNumber] = React.useState<number | null>(null);
1517
const [storage] = useState(() => createAsyncStorage("test-database"));
1618

19+
function reportError(e: any) {
20+
Alert.alert(e?.name ?? "Error", JSON.stringify(e, null, 2));
21+
}
22+
1723
async function readCurrent() {
1824
try {
1925
const value = await storage.getItem(STORAGE_KEY);
2026
setStoredNumber(value ? Number(value) : null);
21-
} catch (e) {
22-
console.error(e);
27+
} catch (e: any) {
28+
reportError(e);
2329
}
2430
}
2531

@@ -31,21 +37,21 @@ function GetSet() {
3137
setStoredNumber(newNumber);
3238
await readCurrent();
3339
} catch (e) {
34-
console.error(e);
40+
reportError(e);
3541
}
3642
};
3743

3844
const removeItem = async () => {
39-
await storage.removeItem(STORAGE_KEY).catch(console.error);
45+
await storage.removeItem(STORAGE_KEY).catch(reportError);
4046
await readCurrent();
4147
};
4248

4349
const listAllKeys = async () => {
4450
try {
45-
const keys = await storage.getKeys();
51+
const keys = await storage.getAllKeys();
4652
Alert.alert("keys", keys.join(", "));
4753
} catch (e) {
48-
console.error(e);
54+
reportError(e);
4955
}
5056
};
5157

@@ -62,7 +68,7 @@ function GetSet() {
6268
<Button title="list all keys" onPress={listAllKeys} />
6369
</View>
6470
);
65-
}
71+
};
6672

6773
const styles = StyleSheet.create({
6874
text: {
@@ -73,6 +79,4 @@ const styles = StyleSheet.create({
7379
},
7480
});
7581

76-
export const STORAGE_KEY = "random";
77-
78-
export default GetSet;
82+
export default BasicCrud;

0 commit comments

Comments
 (0)