Skip to content

Commit e013d94

Browse files
committed
Merge branch 'master' of github.com:pedronauck/react-adopt
* 'master' of github.com:pedronauck/react-adopt: chore: improve readme examples fix: typo on readme
2 parents 3a86911 + 976a184 commit e013d94

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Install as project dependency:
4444
$ yarn add react-adopt
4545
```
4646

47-
Now you can use adopt to compose your components. See above an example using the awesome [react-powerplug](https://github.com/renatorib/react-powerplug):
47+
Now you can use adopt to compose your components. See bellow an example using the awesome [react-powerplug](https://github.com/renatorib/react-powerplug):
4848

4949
![Good](https://i.imgur.com/RXVlFwy.png)
5050

@@ -73,7 +73,7 @@ See [this demo](https://codesandbox.io/s/qv3m6yk2n4?hidenavigation=1) for a bett
7373

7474
### Custom render and retrieving props from composed
7575

76-
Some components don't use the `children` property as render props. For cases like that, you can pass a function as mapper value that will return your component. This function will receive as props the `render` method, the props passed on `Composed` component and the previous values from each mapper. See an example:
76+
Some components don't use the prop called `children` to make work render props. For cases like that, when you define your mapper you can pass a simple function as mapper value that will return your component, instead of a jsx element. This function will receive a prop `render` that will be responsible to make render, the props passed on `Composed` component and the previous values from each mapper. See an example:
7777

7878
```js
7979
import { adopt } from 'react-adopt'
@@ -110,6 +110,28 @@ const Composed = adopt({
110110
</Composed>
111111
```
112112

113+
And get previous mapper results as prop for compose:
114+
115+
```js
116+
import { adopt } from 'react-adopt'
117+
118+
import { User, Cart, ShippingRate } from 'my-containers'
119+
120+
const Composed = adopt({
121+
cart: <Cart />,
122+
user: <User />,
123+
shippingRates: ({ user, cart, render }) => (
124+
   <ShippingRate zipcode={user.zipcode} items={cart.items}>
125+
{render}
126+
</ShippingRate>
127+
)
128+
})
129+
130+
<Composed>
131+
{({ cart, user, shippingRates }) => /* ... */ }
132+
</Composed>
133+
```
134+
113135
### Leading with multiples params
114136

115137
Some render props components return multiple arguments in the children function instead of single one, a simple example in the new [Query](https://www.apollographql.com/docs/react/essentials/queries.html#basic) and [Mutation](https://www.apollographql.com/docs/react/essentials/mutations.html) component from `react-apollo`. In that case, what you can do is a arbitrary render with `render` prop [using you map value as a function](#custom-render-and-retrieving-props-from-composed):

0 commit comments

Comments
 (0)