Skip to content

Instantly share code, notes, and snippets.

@drKnoxy
Created January 4, 2018 17:34
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 drKnoxy/eeb6e70f180f0b4df7baa40afc08e573 to your computer and use it in GitHub Desktop.
Save drKnoxy/eeb6e70f180f0b4df7baa40afc08e573 to your computer and use it in GitHub Desktop.
Redux render prop
const withState = connect(state => ({
visitor: getVisitor(state),
form: getRegForm(state),
activeUsers: getActiveUsers(state),
}));
const HomeData = withState((children, ...rest) => children(...rest) );
// in usage
export function Home() {
return (
<HomeData>
{({ visitor, form, activeUsers }) => (
<div>
<Header>{visitor.firstName}</Header>
<RegForm form={form} />
<ul>
{activeUsers.map(u => (
<li>
<UserCard user={u} />
</li>
))}
</ul>
</div>
)}
</HomeData>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment