Last active
July 16, 2019 20:53
-
-
Save robcalcroft/9c4fbe7538e0fd27bd77e45a209a0b6f to your computer and use it in GitHub Desktop.
Why render props mean messy code
This file contains 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
function App(things) { | |
const newData = useGetNewData(things); | |
function handleClick() { | |
if (newData.length > 0)) { | |
// Woohoo | |
} | |
} | |
return ( | |
<> | |
<h1>Hello</h1> | |
{newData.map(thing => ( | |
<div>{thing} is really cool</div> | |
))} | |
<button type="button" onClick={handleClick}>Click me</button> | |
</> | |
) | |
} |
This file contains 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
function App() { | |
return ( | |
<MyRenderProp data={things}> | |
{({ newData }) => ( | |
<div>{newData.things}</div> | |
)} | |
</MyRenderProp> | |
); | |
} |
This file contains 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
function App() { | |
function handleClick() { | |
if (newData.length > 0)) { | |
// Hmm this is gonna fail as we don't have access to `newData` | |
} | |
} | |
return ( | |
<MyRenderProp data={things}> | |
{({ newData }) => ( | |
<h1>Hello</h1> | |
{newData.map(thing => ( | |
<div>{thing} is really cool</div> | |
))} | |
<button type="button" onClick={handleClick}>Click me</button> | |
)} | |
</MyRenderProp> | |
); | |
} |
This file contains 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
function App() { | |
return ( | |
<MyRenderProp data={things}> | |
{({ newData }) => ( | |
<div>{newData.things}</div> | |
<FormHandlerRenderProp initialValue={newData.otherThing}> | |
{({ values }) => ( | |
<input value={values.thing} /> | |
)} | |
</FormHandlerRenderProp> | |
)} | |
</MyRenderProp> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment