Skip to content

Instantly share code, notes, and snippets.

@alex-boom
Created January 27, 2020 10:15
Show Gist options
  • Save alex-boom/cc2896659243ab1917b0d6aab6a8d5a1 to your computer and use it in GitHub Desktop.
Save alex-boom/cc2896659243ab1917b0d6aab6a8d5a1 to your computer and use it in GitHub Desktop.
useContext
import React, {useContext} from "react";
import "./styles.css";
const MyContext = React.createContext();
export default function App() {
return (
<MyContext.Provider value="Hello">
<Child />
</MyContext.Provider>
);
}
const Child = () => {
const value = useContext(MyContext);
return <p>{value}</p>
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment