Skip to content

Instantly share code, notes, and snippets.

@flipjs
Forked from iammerrick/ConnectNavigation.js
Created April 24, 2016 15:59
Show Gist options
  • Save flipjs/1af50fab2fe079c24b6be82094ea045a to your computer and use it in GitHub Desktop.
Save flipjs/1af50fab2fe079c24b6be82094ea045a to your computer and use it in GitHub Desktop.
A higher order "smart" component that encapsulates all the logic for fetching and storing state. Especially smart because it accepts any "dumb" component, dumb components can be dropped on a page without knowing about their smart parents.
import React from 'react';
import { connect } from 'react-redux';
import { selectNavigation, selectState } from 'state/home/navigation/navigationSelectors';
import { getNavigation } from 'state/home/navigation/navigationActions';
const ConnectHomeNavigation = (Component) => {
return connect((state) => ({
navigation: selectNavigation(state),
state: selectState(state)
}), {
getNavigation
})(class extends React.Component {
componentDidMount() {
this.props.getNavigation();
}
render() {
return <Component state={this.props.state} navigation={this.props.navigation} />;
}
});
};
export default ConnectHomeNavigation;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment