Skip to content

Instantly share code, notes, and snippets.

@sajithdilshan
Created January 27, 2018 20:11
Show Gist options
  • Save sajithdilshan/d16cf74b036daa2dca9ac5ff2bdf055f to your computer and use it in GitHub Desktop.
Save sajithdilshan/d16cf74b036daa2dca9ac5ff2bdf055f to your computer and use it in GitHub Desktop.
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