Skip to content

Instantly share code, notes, and snippets.

@joboccara
Created April 23, 2021 07:20
Show Gist options
  • Save joboccara/c54a08b215b93dafb59a59f8c0e22b87 to your computer and use it in GitHub Desktop.
Save joboccara/c54a08b215b93dafb59a59f8c0e22b87 to your computer and use it in GitHub Desktop.
const CountContext = React.createContext(null);
const CountContextProvider = ({ children }) => {
const [count, setCount] = React.useState(0);
const onClickMemo = () =>
window.alert(`clickMemo, count: ${count}`);
return (
<CountContext.Provider value={{ count, setCount }}>
<GrandParent>{children}</GrandParent>
<MemoComponent onClick={onClickMemo} />
</CountContext.Provider>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment