'init'
This commit is contained in:
34
app/providers/DatabaseProvider/DatabaseProvider.tsx
Normal file
34
app/providers/DatabaseProvider/DatabaseProvider.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import { useDatabase } from "@/app/providers/DatabaseProvider/useDatabase";
|
||||
import { useEffect, useState } from "react";
|
||||
import { createContext } from "react";
|
||||
import { TABLES } from "./tables";
|
||||
|
||||
export const DatabaseContext = createContext<any>({});
|
||||
|
||||
interface DatabaseProviderProps {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export function DatabaseProvider(props: DatabaseProviderProps) {
|
||||
const [initialized, setInitialized] = useState(false);
|
||||
const {runQuery} = useDatabase();
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
await createAllTables();
|
||||
setInitialized(true);
|
||||
})();
|
||||
}, []);
|
||||
|
||||
const createAllTables = async () => {
|
||||
for(let i = 0; i < TABLES.length; i++){
|
||||
await runQuery(TABLES[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<DatabaseContext.Provider value={{}}>
|
||||
{initialized && props.children}
|
||||
</DatabaseContext.Provider>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user