Created
January 4, 2018 17:34
-
-
Save drKnoxy/eeb6e70f180f0b4df7baa40afc08e573 to your computer and use it in GitHub Desktop.
Redux render prop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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