Skip to content

Instantly share code, notes, and snippets.

@tdeekens
Last active April 28, 2018 13:48
Show Gist options
  • Save tdeekens/6e28f85e442de713cd785f7da5aedbc0 to your computer and use it in GitHub Desktop.
Save tdeekens/6e28f85e442de713cd785f7da5aedbc0 to your computer and use it in GitHub Desktop.
class RadioGroup extends React.Component {
getOptionProps = () => ({
name: this.props.name,
value: this.props.value,
onChange: this.handleChange
});
render() {
return this.props.children({
getOptionProps: this.getOptionProps
});
}
}
class UIComponent extends React.Component {
handleChange = event => {};
render() {
return (
<RadioGroup
name="size"
value={this.props.tshirt.value}
onChange={this.handleChange}
>
{({ getOptionProps }) => (
<React.Fragment>
<RadioOption {...getOptionProps()} value="m">
M
</RadioOption>
{/* two more of these with the respective props */}
</React.Fragment>
)}
</RadioGroup>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment