Skip to content

Instantly share code, notes, and snippets.

@iammerrick
Last active May 30, 2023 20:06
Show Gist options
  • Save iammerrick/873b34ca9443fd593817840b5b94819f to your computer and use it in GitHub Desktop.
Save iammerrick/873b34ca9443fd593817840b5b94819f 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