Created
July 15, 2019 13:08
-
-
Save zonzujiro/f1a86e5a24fe6193be2f32091ad2a839 to your computer and use it in GitHub Desktop.
This file contains 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
const processRequest = requestPromise => async dispatch => { | |
const result = async requestPromise() | |
if (isError(result)) { | |
dispatch(resetToken()) | |
} | |
return result | |
} |
This file contains 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 { 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