Skip to content

Instantly share code, notes, and snippets.

@rao123dk
Last active January 27, 2019 08:20
Show Gist options
  • Save rao123dk/9ba0b67ff4a8cb34841b4ba5e9fb6ee9 to your computer and use it in GitHub Desktop.
Save rao123dk/9ba0b67ff4a8cb34841b4ba5e9fb6ee9 to your computer and use it in GitHub Desktop.
//Util.js
export function reactBind(data,that){
return data.forEach((fn) => that[fn] = that[fn].bind(that));
}
//myNewComponet.jsx
import reactBind from './Util.js';
class myNewComponet extends React.Component{
constructor(props) {
super(props);
// Not this
//this.onChange = this.onChange.bind(this);
reactBind(['onChange','onItemClick','onListClick'], this); // OK
}
/*
rest code
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment