Skip to content

Instantly share code, notes, and snippets.

@cyan33
Created May 28, 2018 06:24
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 cyan33/963ea414262f0ae39eef5cddb591db55 to your computer and use it in GitHub Desktop.
Save cyan33/963ea414262f0ae39eef5cddb591db55 to your computer and use it in GitHub Desktop.
Usage of react render props
// This is a stupid example of using render props when I was
// reading the doc of React.children
const React = require('react');
class CountSiblings extends React.Component {
render() {
const {children} = this.props;
return children(
React.Children.count(children),
);
}
}
// usage
<CountSiblings>
{count => (
<>
<Child1 count={count} />
<Child2 count={count} />
<Child3 count={count} />
</>
)}
</CountSiblings>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment