mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Add useFS hook
This commit is contained in:
11 files changed
+198
-199
No files matched your search
@@ -0,0 +1,29 @@
|
||||
import { createContext, useContext, type ReactNode } from 'react';
|
||||
import LightningFS from '@isomorphic-git/lightning-fs';
|
||||
|
||||
interface FSContextType {
|
||||
fs: LightningFS.PromisifiedFS;
|
||||
}
|
||||
|
||||
const FSContext = createContext<FSContextType | undefined>(undefined);
|
||||
|
||||
interface FSProviderProps {
|
||||
children: ReactNode;
|
||||
fs: LightningFS.PromisifiedFS;
|
||||
}
|
||||
|
||||
export function FSProvider({ children, fs }: FSProviderProps) {
|
||||
return (
|
||||
<FSContext.Provider value={{ fs }}>
|
||||
{children}
|
||||
</FSContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useFS(): FSContextType {
|
||||
const context = useContext(FSContext);
|
||||
if (context === undefined) {
|
||||
throw new Error('useFS must be used within a FSProvider');
|
||||
}
|
||||
return context;
|
||||
}
|
||||
Reference in new issue
Block a user