You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+27Lines changed: 27 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,7 @@
14
14
-[Usage](#--usage-demo)
15
15
-[Working with new Context api](#working-with-new-context-api)
16
16
-[Custom render and retrieving props from composed](#custom-render-and-retrieving-props-from-composed)
17
+
-[Mapping props from mappers](#mapping-props-from-mappers)
17
18
-[Leading with multiple params](#leading-with-multiple-params)
18
19
-[Typescript support](#typescript-support)
19
20
-[Inline composition](#inline-composition)
@@ -133,6 +134,32 @@ const Composed = adopt({
133
134
</Composed>
134
135
```
135
136
137
+
### Mapping props from mappers
138
+
139
+
Sometimes get properties from your mappers can be kind a boring depending how nest is the result from each mapper. To easily avoid deep nested objects or combine your results, you can map the final results into a single object using de `mapProps` function as second parameter.
140
+
141
+
```js
142
+
import { adopt } from'react-adopt'
143
+
import { Value } from'react-powerplug'
144
+
145
+
constmapper= {
146
+
greet:<Value initial="Hi"/>,
147
+
name:<Value initial="John"/>,
148
+
}
149
+
150
+
constmapProps= ({ greet, name }) => ({
151
+
message:`${greet.value}${name.value}`,
152
+
})
153
+
154
+
constComposed=adopt(mapper, mapProps)
155
+
156
+
constApp= () => (
157
+
<Composed>
158
+
{({ message }) =>/* ... */}
159
+
</Composed>
160
+
)
161
+
```
162
+
136
163
### Leading with multiple params
137
164
138
165
Some render props components return multiple arguments in the children function instead of a single one (see 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 this case, you can do an arbitrary render with `render` prop [using your map value as a function](#custom-render-and-retrieving-props-from-composed):
0 commit comments