-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
35 lines (30 loc) · 1.02 KB
/
App.js
File metadata and controls
35 lines (30 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { SQLiteProvider } from "expo-sqlite";
import UserForm from "./components/Userform";
import UserList from "./components/UserList";
import { useState } from "react";
export default function App() {
const [needsRefresh, setNeedsRefresh] = useState(false);
// This flag is used to trigger a refresh in the UserList component
// Whenever a new user is added or deleted, the UserList will re-fech the data
return (
<SQLiteProvider
databaseName="userDatabase.db"
onInit={async (db) => {
await db.execAsync(`
CREATE TABLE IF NOT EXISTS users(
id INTEGER PRIMARY KEY AUTOINCREMENT,
firstName TEXT NOT NULL,
lastName TEXT NOT NULL,
email TEXT NOT NULL UNIQUE,
phone TEXT NOT NULL
);
PRAGMA journal_mode=WAL;
`);
}}
options={{useNewConnection: false}}
>
<UserForm onSuccess={() => setNeedsRefresh(prev => !prev)} />
<UserList needsRefresh={needsRefresh} />
</SQLiteProvider>
);
}