I have my below code. But the radio buttons are not checking or unchecking on click.
const Radio = props => {
const { name } = props;
return (
<div>
<input
id={name}
type="radio"
name="type"
value={name}
checked={this.state.selectedOption === { name }}
onClick={this.handleChange.bind(this)}
/>
<label for={name}>{name}</label>
</div>
);
};
With a handleChange event handler.
handleChange = e => {
this.setState({
selectedOption: e.target.value
});
};
I have defined the selectedOption in my constructor.
constructor(props) {
super(props);
this.state = {
error: null,
isLoaded: false,
selectedOption: "",
QuestionAnswer: [],
counter: 0
};
}
What am I doing wrong?