Created
October 26, 2017 13:15
-
-
Save anonymous/5c6c14e2d2503b4d22872b983bccd978 to your computer and use it in GitHub Desktop.
Fetch API Post example
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 React, { Component } from "react"; | |
import { connect } from "react-redux"; | |
import PropTypes from "prop-types"; | |
import history from '../../components/utility/history'; | |
export default function(ComposedComponent) { | |
class Authentication extends Component { | |
static contextTypes = { | |
router: PropTypes.object | |
}; | |
componentWillMount() { | |
if (!this.props.authenticated) { | |
history.push("/"); | |
} | |
} | |
componentWillUpdate(nextProps) { | |
if (!nextProps.authenticated) { | |
history.router.push("/"); | |
} | |
} | |
render() { | |
return <ComposedComponent {...this.props} />; | |
} | |
} | |
function mapStateToProps(state) { | |
return { authenticated: state.auth.isauth }; | |
} | |
return connect(mapStateToProps)(Authentication); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment