Created
January 27, 2018 20:11
-
-
Save sajithdilshan/d16cf74b036daa2dca9ac5ff2bdf055f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import ColorAppStore from "../stores/ColorAppStore"; | |
export default class ColorComponent extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
color: ColorAppStore.getActiveColor() | |
} | |
} | |
componentDidMount() { | |
ColorAppStore.on("storeUpdated", this.updateBackgroundColor); | |
} | |
componentWillUnmount() { | |
ColorAppStore.removeListener("storeUpdated", this.updateBackgroundColor); | |
} | |
updateBackgroundColor = () => { | |
this.setState({color: ColorAppStore.getActiveColor()}) | |
}; | |
render() { | |
return ( | |
<div className="color-container" style={{backgroundColor: this.state.color}}/> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment