Skip to content

Instantly share code, notes, and snippets.

Created October 26, 2017 13:15
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 anonymous/5c6c14e2d2503b4d22872b983bccd978 to your computer and use it in GitHub Desktop.
Save anonymous/5c6c14e2d2503b4d22872b983bccd978 to your computer and use it in GitHub Desktop.
Fetch API Post example
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