Skip to content

Instantly share code, notes, and snippets.

@yowchun93
Last active April 6, 2020 13:36
Show Gist options
  • Save yowchun93/0d1b38c92d33a908c55e5151e6d126d1 to your computer and use it in GitHub Desktop.
Save yowchun93/0d1b38c92d33a908c55e5151e6d126d1 to your computer and use it in GitHub Desktop.
Children render props
export default function App() {
return (
<div className="App">
<Toggle
render={(on, toggle) => (
<div>
{on && <h1>Hello</h1>}
<button onClick={() => toggle()}>toggle</button>
</div>
)}
/>
</div>
);
}
const Toggle = ({ render }) => {
const [on, setToggle] = React.useState(true);
return (
<div>
{render({
on: on,
toggle: setToggle
})}
</div>
);
};
const ToggleRPC = ({ children }) => {
const [on, setToggle] = React.useState(true);
return children({
on: on,
toggle: setToggle
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment