Hi all, I have a question surrounding global state and typescript.
// Foo.tsx
export const GlobalContext = createContext({})
export const useGlobalContext = () => useContext(GlobalContext)
function Foo(): JSX.Element() {
const myService = useInterpret(myMachine)
<GlobalContext.Provider value={{ myService }}>
<Bar />
</GlobalContext.Provider>
}
Then down in Bar.tsx:
// Bar.tsx
function Bar(): JSX.Element() {
// ERROR: Property `myService` does not exist on type {}
const { myService } = useGlobalContext()
return (
<div>
</div>
)
}
So I get the error:
ERROR: Property `myService` does not exist on type {}
Thing I'm struggling with is how to type things properly here specifically in those first two lines:
export const GlobalContext = createContext({})
export const useGlobalContext = () => useContext(GlobalContext)
Can anyone help?