import React, { useState, useContext } from 'react' // 1. Define data that the context holds, plus a setter to update data interface MyContextProps { standalone: boolean setMyContext: (value: Partial>) => void } // 2. Create the actual context with some default data const MyAppContext = React.createContext({ standalone: true, setMyContext: () => {} }) // 3. Define the context provider export const MyContextProvider: React.FC<{ value: MyContextProps }> = ({ value: initialValue, children }) => { const [states, setStates] = useState(initialValue) return ( { setStates({ ...states, ...props }) } }}> {children} ) } // 4. Make a hook to use the context easier export const useMyContext = () => useContext(MyAppContext) // 5. Use the context provider in some root (i.e: App.tsx) // // 6. Use hook to get and set context data // const { foobar, setContext } = useMyContext() // ... /// setContext({ foobar: !foobar })