Browse Source

Use functional component

main
Alex Krolick 7 years ago
parent
commit
69198013e1
  1. 26
      examples/context/theme-detailed-themed-button.js

26
examples/context/theme-detailed-themed-button.js

@ -1,19 +1,17 @@
import {ThemeContext} from './theme-context';
class ThemedButton extends React.Component {
// highlight-range{3-10}
render() {
return (
<ThemeContext.Consumer>
{theme => (
<button
{...this.props}
style={{backgroundColor: theme.background}}
/>
)}
</ThemeContext.Consumer>
);
}
function ThemedButton(props) {
// highlight-range{2-9}
return (
<ThemeContext.Consumer>
{theme => (
<button
{this.props}
style={{backgroundColor: theme.background}}
/>
)}
</ThemeContext.Consumer>
);
}
export default ThemedButton;

Loading…
Cancel
Save