Skip to content

Instantly share code, notes, and snippets.

@diego3g
Created April 16, 2018 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diego3g/460648bef94f21bacea05470c7f73dfc to your computer and use it in GitHub Desktop.
Save diego3g/460648bef94f21bacea05470c7f73dfc to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
const ThemeContext = React.createContext('light');
class App extends Component {
state = {
theme: 'light',
};
changeTheme = () => {
this.setState({
theme: this.state.theme === 'light'
? 'dark'
: 'light'
});
}
render() {
return (
<ThemeContext.Provider value={this.state.theme}>
<button onClick={this.changeTheme}>Alterar tema</button>
<ThemedButton />
</ThemeContext.Provider>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment