Last active
October 16, 2017 15:14
-
-
Save ryanflorence/a0b603af5a59423a45716d8f67e08844 to your computer and use it in GitHub Desktop.
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 SomeScreen = () => ( | |
<div> | |
<Blah /> | |
<Categories | |
render={categories => ( | |
<Expenses | |
render={expenses => ( | |
<div> | |
{groupExpensesByCategory(categories, expenses).map(category => ( | |
<RandomScreen {...category} /> | |
))} | |
</div> | |
)} | |
/> | |
)} | |
/> | |
</div> | |
) | |
// if it’s too noisy, pull it out into a component with some copy/paste action | |
const ExpensesByCategory = ({ render }) => ( | |
<Categories | |
render={categories => ( | |
<Expenses | |
render={expenses => | |
render(groupExpensesByCategory(categories, expenses))} | |
/> | |
)} | |
/> | |
) | |
const SomeScreen = () => ( | |
<div> | |
<Blah /> | |
<ExpensesByCategory render={category => <RandomScreen {...category} />} /> | |
</div> | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As I said in this tweet, you can create a compose helper similar to that one I created on react-powerplug: https://github.com/renatorib/react-powerplug/blob/master/src/utils/compose.js
In that specific case, it's will be something like this:
Then, compose:
If you find compose function ugly, you can change compose function to get prop names by
element.type.name || element.type.displayName
if you don't want to pass another array, but I did not recommend, since they can not be relied upon in production. Also you can change the API to pass in a different way, example:Etc.