Skip to content

Instantly share code, notes, and snippets.

@tdeekens
Created December 16, 2017 14:03
Show Gist options
  • Save tdeekens/8c1a320d3fb234b318f4a46cdb748a95 to your computer and use it in GitHub Desktop.
Save tdeekens/8c1a320d3fb234b318f4a46cdb748a95 to your computer and use it in GitHub Desktop.
class RadioGroup extends React.Component {
static childContextTypes = {
radioGroup: PropTypes.shape({
onChange: PropTypes.function,
value: PropTypes.string,
name: PropTypes.string
})
};
getChildContext() {
return {
radioGroup: {
onChange: this.handleChange,
value: this.props.value,
name: this.props.name
}
};
}
render() {}
}
class RadioOption extends React.Component {
static contextTypes = {
radioGroup: {
onChange: this.handleChange,
value: this.props.value,
name: this.props.name
}
};
render() {
return (
<input
name={this.context.radioGroup.name}
checked={this.context.radioGroup.value === this.props.value}
onChange={this.context.radioGroup.onChange}
/>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment