Skip to content

Instantly share code, notes, and snippets.

@ties
Created March 5, 2017 14:40
Show Gist options
  • Save ties/ee929cccc24165e4a470f9048b714e6a to your computer and use it in GitHub Desktop.
Save ties/ee929cccc24165e4a470f9048b714e6a to your computer and use it in GitHub Desktop.
/**
* An higher order component that provides the 'isAuthenticated' prop to it's
* children
*/
import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import { createStructuredSelector } from 'reselect';
import { selectIsAuthenticated } from './selectors';
function IsAuthenticated({ isAuthenticated, children }) {
return React.cloneElement(children, { isAuthenticated });
}
IsAuthenticated.propTypes = {
isAuthenticated: PropTypes.bool.isRequired,
children: PropTypes.element,
};
const mapStateToProps = () => createStructuredSelector({
isAuthenticated: selectIsAuthenticated(),
});
export default connect(mapStateToProps)(IsAuthenticated);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment