Skip to content

Instantly share code, notes, and snippets.

@vivekascoder
Created July 10, 2020 06:45
Show Gist options
  • Save vivekascoder/92031f5a4e144ceac2cbbcd7551347e3 to your computer and use it in GitHub Desktop.
Save vivekascoder/92031f5a4e144ceac2cbbcd7551347e3 to your computer and use it in GitHub Desktop.
import React from "react";
import ReactDOM from "react-dom";
import "./styles.css";
const root = document.getElementById("root");
const ThemeContext = React.createContext("light");
function Toolbar(props) {
return (
<div>
<Button />
</div>
);
}
class Button extends React.Component {
static contextType = ThemeContext;
render() {
return <input type="button" value="CLick Me" theme={this.context} />;
}
}
class App extends React.Component {
render() {
return (
<ThemeContext.Provider value="dark">
<Toolbar />
</ThemeContext.Provider>
);
}
}
ReactDOM.render(<App />, root);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment