Skip to content

Instantly share code, notes, and snippets.

@stwgabriel
Created September 28, 2022 14:00
Show Gist options
  • Save stwgabriel/830345b8c594f69838c30258e3e44d21 to your computer and use it in GitHub Desktop.
Save stwgabriel/830345b8c594f69838c30258e3e44d21 to your computer and use it in GitHub Desktop.
useContext base
import {
createContext,
useMemo,
useState,
} from 'react';
const Context = createContext({});
function Provider({ children }) {
// States
const [data, setData] = useState(null)
// Provider MEMO
const providerData = useMemo(() => ({
data, setData,
}), [data])
return (
<Context.Provider value={providerData}>
{children}
</Context.Provider>
)
}
export default Provider;
export { Context };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment