Skip to content

Commit 42e0dab

Browse files
committed
chore: example how to interop with a render-prop library
1 parent 40afa30 commit 42e0dab

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,30 @@ const App = () => (
272272
)
273273
```
274274
275+
#### Use `createRender` to interop with a library which only supports function as render-prop
276+
277+
[![Edit](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/1qyqwq14jq)
278+
279+
```js
280+
import Toggle from 'react-toggled'
281+
282+
const Toggler = ({on, getTogglerProps, onLabel, offLabel}) => (
283+
<div>
284+
<button {...getTogglerProps()}>Toggle me</button>
285+
<div>{on ? onLabel : offLabel}</div>
286+
</div>
287+
)
288+
289+
Toggler.defaultProps = {
290+
onLabel: 'Toggled On',
291+
offLabel: 'Toggled Off',
292+
}
293+
294+
const ToggleView = createRender(Toggler)
295+
296+
const App = () => <Toggle>{ToggleView}</Toggle>
297+
```
298+
275299
## Other Solutions
276300
277301
- [`render-props`](https://github.com/donavon/render-props)

0 commit comments

Comments
 (0)