Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const withPropsChanged = (arePropsChagned, callback) => BaseComponent => {
- const factory = React.createFactory(BaseComponent)
- return class Watcher extends React.Component {
- componentWillReceiveProps(nextProps) {
- if (arePropsChagned(this.props, nextProps)) {
- callback(nextProps)
- }
- }
- render() {
- return factory(this.props)
- }
- }
- }
- // usage
- withPropsChanged(
- (props, nextProps) =>
- props.path != nextProps.path,
- props => props.selectItem(null)
- ),
Add Comment
Please, Sign In to add comment