Alex Krolick
7 years ago
3 changed files with 43 additions and 0 deletions
@ -0,0 +1,11 @@ |
|||||
|
const Button = ({theme, children}) => ( |
||||
|
<button className={theme ? 'dark' : 'light'}> |
||||
|
{children} |
||||
|
</button> |
||||
|
); |
||||
|
|
||||
|
export default React.forwardRef((props, ref) => ( |
||||
|
<ThemeContext.Consumer> |
||||
|
{theme => <Button {...props} theme={theme} ref={ref} />} |
||||
|
</ThemeContext.Consumer> |
||||
|
)); |
@ -0,0 +1,20 @@ |
|||||
|
class Button extends React.Component { |
||||
|
componentDidMount() { |
||||
|
alert(this.props.theme); |
||||
|
} |
||||
|
|
||||
|
render() { |
||||
|
const {theme, children} = this.props; |
||||
|
return ( |
||||
|
<button className={theme ? 'dark' : 'light'}> |
||||
|
{children} |
||||
|
</button> |
||||
|
); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export default props => ( |
||||
|
<ThemeContext.Consumer> |
||||
|
{theme => <Button {...props} theme={theme} />} |
||||
|
</ThemeContext.Consumer> |
||||
|
); |
Loading…
Reference in new issue