Last active
April 3, 2018 22:29
-
-
Save renatorib/4ab1607bff40f3cf25332af5f87088d8 to your computer and use it in GitHub Desktop.
different ways to use two render props in one component
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
// 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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1st and 2nd will break compose utilities like
react-adopt
and powerplug'scompose