Skip to content

Instantly share code, notes, and snippets.

@jide
Last active December 19, 2017 02:31
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 jide/94f6366bc612e09c5cc8ac651c85fd7f to your computer and use it in GitHub Desktop.
Save jide/94f6366bc612e09c5cc8ac651c85fd7f to your computer and use it in GitHub Desktop.
More complex optimized redux connectors.
import { connect } from 'react-redux';
import { removeUser } from '../reducers/user';
import Users from '../components/Users';
const Container = connect(
(state, props) => ({
users: state.users.all,
options: state.options,
isAdmin: state.currentUser[props.userId].isAdmin === true
}),
{ removeUser },
null,
{
areStatesEqual: (next, prev) => {
return (
prev.users.all === next.users.all &&
prev.options === next.options &&
prev.currentUser === next.currentUser
);
}
}
)(Users);
export default Container;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment