Skip to content

Instantly share code, notes, and snippets.

@adamterlson
Created October 13, 2016 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamterlson/afa438dc62687038ae0a711f36c75a4d to your computer and use it in GitHub Desktop.
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?
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);
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