Skip to content

Instantly share code, notes, and snippets.

@zonzujiro
Created July 15, 2019 13:08
Show Gist options
  • Save zonzujiro/f1a86e5a24fe6193be2f32091ad2a839 to your computer and use it in GitHub Desktop.
Save zonzujiro/f1a86e5a24fe6193be2f32091ad2a839 to your computer and use it in GitHub Desktop.
const processRequest = requestPromise => async dispatch => {
const result = async requestPromise()
if (isError(result)) {
dispatch(resetToken())
}
return result
}
import { getData } from './api/users'
import { processRequest } from './redux/token'
const mapStateToProps = state => {
isAuthenticated: Boolean(state.authentication.jwtToken)
}
const mapDispatchToProps = { processRequest }
class SomeComponent extends React.Component {
componentDidMount() {
this.props.processRequest(getData())
}
render() {
const { isAuthenticated } = this.props;
return isAuthenticated ? <div class='content'/> : <div class='access-denied' />
}
}
export default connect(mapStateToProps, mapDispatchToProps)(SomeComponent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment