Last active
December 1, 2015 11:58
-
-
Save wuct/cba6e53cad3a17c0a977 to your computer and use it in GitHub Desktop.
add and remove listner
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 MyStore from './MyStore'; | |
class MyComponent extends React.Component { | |
componentDidMount() { | |
MyStore.addChangeListener(this._onChange.bind(this)); | |
} | |
componentWillUnmount() { | |
MyStore.removeChangeListener(this._onChange.bind(this)); // not working | |
MyStore.removeChangeListener(this._onChange); // not working, too | |
} | |
render() { | |
return ( | |
<div></div> | |
); | |
} | |
_onChange(){ | |
this.setState(/* set something */); | |
} | |
} | |
export default MyComponent; |
jchouse
commented
Dec 1, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment