Skip to content

Instantly share code, notes, and snippets.

@joedski
Last active September 19, 2017 01:54
Show Gist options
  • Save joedski/993a2085ec15cf385c2c1e4e25770f20 to your computer and use it in GitHub Desktop.
Save joedski/993a2085ec15cf385c2c1e4e25770f20 to your computer and use it in GitHub Desktop.
hof thunks: A connected component
import { myEndpoint } from 'my-app/api/thunks';
// ... other sundry imports.
export default compose(
connect(
null,
(dispatch, ownProps) => ({
getMyResource: dispatch(myEndpoint({
name: ownProps.name,
order: 'asc',
})),
})
)
)(class MyResourceDisplay extends PureComponent {
handleClick(event) {
event.preventDefault();
const { result, error } =
await this.props.getMyResource({
name: 'foo',
order: 'asc',
});
if (error) {
this.setState({
status: 'error',
lastError: error,
// not clearing result.
});
}
else {
this.setState({
status: 'success',
hasReceivedBefore: true,
lastError: null,
result,
});
}
}
// ... other componenty stuff here.
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment