I'm following Pure React, and there's a House
component that needs some building (omitted the imports for brevity):
class House extends React.Component {
state = {
bathroom: true,
bedroom: false,
kitchen: true,
livingRoom: false
}
flipSwitch = (action) => {
this.setState({
???????????????
});
}
render () {
return (
<>
<RoomButton room='kitchen' handler={this.flipSwitch}/>
<RoomButton room='bathroom' handler={this.flipSwitch}/>
<RoomButton room='livingRoom' handler={this.flipSwitch}/>
<RoomButton room='bedroom' handler={this.flipSwitch}/>
</>
);
}
}
const RoomButton = ({room, handler}) => (
<button onClick={handler}>
{`Flip light in ${room}!`}
</button>
)
ReactDOM.render (
<House/>,
document.getElementById('root')
)
Desired outcome: when you click the <room>
button, the state of the House
component changes to reflect the flipping of the lightswitch in the room (i.e. true is light on, false is light off).
I'm wondering what should go instead of the ?????
- how do I pass the room
prop into the handler
function from inside a given RoomButton
component?
Tried just passing it in, and got a Maximum depth reached
error from React.
ES6 answers would be most appreciated, BTW.