Skip to content

Instantly share code, notes, and snippets.

@renatorib
Last active April 3, 2018 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renatorib/4ab1607bff40f3cf25332af5f87088d8 to your computer and use it in GitHub Desktop.
Save renatorib/4ab1607bff40f3cf25332af5f87088d8 to your computer and use it in GitHub Desktop.
different ways to use two render props in one component
// passing object to render with two fns (opener & content, for example)
<Modal>
{{
opener: ({ open }) => <button onClick={open}>Open Modal</button>,
content: {{ close }) => <div><h2>Hi modal</h2> <button onClick={close}>Close me</button></div>
}}
</Modal>
// passing as children array
// https://stackblitz.com/edit/react-array-render-props
<Modal>
{({ open }) => <button onClick={open}>Open Modal</button>}
{({ close }) => <div><h2>Hi modal</h2> <button onClick={close}>Close me</button></div>}
</Modal>
// passing in 2 different props (children & content, for example)
<Modal content={({ close }) => <div><h2>Hi modal</h2> <button onClick={close}>Close me</button></div>}>
{({ open }) => <button onClick={open}>Open Modal</button>}
</Modal>
@renatorib
Copy link
Author

renatorib commented Apr 3, 2018

1st and 2nd will break compose utilities like react-adopt and powerplug's compose

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment