feat: database context
This commit is contained in:
23
web/src/context/db/provider.tsx
Normal file
23
web/src/context/db/provider.tsx
Normal file
@ -0,0 +1,23 @@
|
||||
import { useCallback, useState, type FC, type ReactNode } from "react";
|
||||
import { DbContext } from "./db";
|
||||
|
||||
interface IDBProvider {
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
export const DbProvider: FC<IDBProvider> = ({ children }) => {
|
||||
const [db, _setDb] = useState<IDBDatabase | null>(null);
|
||||
|
||||
const setDb = useCallback((db: IDBDatabase) => _setDb(db), []);
|
||||
|
||||
return (
|
||||
<DbContext.Provider
|
||||
value={{
|
||||
db,
|
||||
setDb,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</DbContext.Provider>
|
||||
);
|
||||
};
|
Reference in New Issue
Block a user