-
-
Save tdeekens/8c1a320d3fb234b318f4a46cdb748a95 to your computer and use it in GitHub Desktop.
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
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