-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLightSwitch.jsx
More file actions
29 lines (26 loc) · 942 Bytes
/
Copy pathLightSwitch.jsx
File metadata and controls
29 lines (26 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import React, { Component } from 'react';
import LightCircuit from '../context/context'
class LightSwitch extends Component {
constructor(props){
super(props)
this.state = {up: false}
}
render() {
return <LightCircuit.Consumer>
{
({flipSwitch}) => {
const handleClick = () => {
this.setState({up: !this.state.up})
flipSwitch()
}
return <button
onClick={handleClick}
className={'light-switch' +
(this.state.up ? ' up' : ' down') +
' ' + this.props.className }><div>Off</div></button>
}
}
</LightCircuit.Consumer>
}
}
export default LightSwitch