mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
29 lines
710 B
TypeScript
29 lines
710 B
TypeScript
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;
|
|
} |