Created
October 13, 2016 21:51
-
-
Save adamterlson/afa438dc62687038ae0a711f36c75a4d to your computer and use it in GitHub Desktop.
Bug: React will blur on every key press when this HOC is used. Due to the component returned not being the same?
This file contains hidden or 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
compose( | |
ownState( | |
set => ({ | |
setValue: e => set(state => ({ | |
...state, | |
value: e.target.value, | |
})), | |
clearValue: () => set(state => ({ | |
...state, | |
value: '', | |
})) | |
}), | |
{ value: '' }, | |
), | |
updateStore( | |
store, | |
set => ({ | |
saveTodo: description => | |
set(state => ({ | |
...state, | |
todos: [ | |
...state.todos, | |
{ description } | |
], | |
})), | |
}) | |
), | |
withProps(({ saveTodo, clearValue }) => | |
keyMap({ | |
Enter: e => { | |
saveTodo(e.target.value); | |
clearValue(); | |
}, | |
Escape: clearValue, | |
}) | |
), | |
propMap( | |
props => ({ | |
...props, | |
onChange: props.setValue, | |
}) | |
) | |
)(TextInput); |
This file contains hidden or 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'; | |
export default cb => Component => { | |
class WithPropsHOC extends React.PureComponent { | |
render() { | |
const props = this.props; | |
const Child = cb(props)(Component); | |
return <Child {...props} /> | |
} | |
} | |
return WithPropsHOC; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment