ATProto forum built with ESAV
at main 750 B view raw
1import React, { createContext, useContext, useState } from 'react'; 2 3type StringStoreContextType = { 4 value: string; 5 setString: (newVal: string) => void; 6}; 7 8const StringStoreContext = createContext<StringStoreContextType | null>(null); 9 10export const StringStoreProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { 11 const [value, setValue] = useState(''); 12 13 return ( 14 <StringStoreContext.Provider value={{ value, setString: setValue }}> 15 {children} 16 </StringStoreContext.Provider> 17 ); 18}; 19 20export const useStringStore = (): StringStoreContextType => { 21 const context = useContext(StringStoreContext); 22 if (!context) throw new Error('useStringStore must be used within a StringStoreProvider'); 23 return context; 24};