10 lines
382 B
TypeScript
10 lines
382 B
TypeScript
import { createContext, useContext } from 'react';
|
|
import type { Prefs } from './prefs';
|
|
|
|
export interface PrefsApi { prefs: Prefs; update: (p: Prefs) => void }
|
|
export const PrefsContext = createContext<PrefsApi | null>(null);
|
|
export const usePrefs = (): PrefsApi => {
|
|
const p = useContext(PrefsContext);
|
|
if (!p) throw new Error('usePrefs outside PrefsContext');
|
|
return p;
|
|
};
|