You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
551 B
27 lines
551 B
7 years ago
|
// highlight-next-line
|
||
|
const ThemeContext = React.createContext('light');
|
||
|
|
||
|
class ThemeProvider extends React.Component {
|
||
|
state = {theme: 'light'};
|
||
|
|
||
|
render() {
|
||
7 years ago
|
// highlight-range{2-4}
|
||
7 years ago
|
return (
|
||
|
<ThemeContext.Provider value={this.state.theme}>
|
||
|
{this.props.children}
|
||
|
</ThemeContext.Provider>
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class ThemedButton extends React.Component {
|
||
|
render() {
|
||
|
// highlight-range{2-4}
|
||
|
return (
|
||
|
<ThemeContext.Consumer>
|
||
7 years ago
|
{theme => <Button theme={theme} />}
|
||
7 years ago
|
</ThemeContext.Consumer>
|
||
|
);
|
||
|
}
|
||
|
}
|