Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // example Context object
- const ThemeContext = React.createContext("dark");
- // usage with context Consumer
- function Button() {
- return <ThemeContext.Consumer>
- {theme => <button className={theme}> Amazing button </button>}
- </ThemeContext.Consumer>
- }
- // usage with useContext hook
- import {useContext} from 'react';
- function ButtonHooks() {
- const theme = useContext(ThemeContext)
- return <button className={theme}>Amazing button</button>
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement