How to use radio buttons in ReactJS?

前端 未结 10 2142
再見小時候
再見小時候 2020-11-27 10:05

I am new to ReactJS, sorry if this sounds off. I have a component that creates several table rows according to the received data.

Each cell within the column has a

10条回答
  •  再見小時候
    2020-11-27 10:26

    To build upon ChinKang said for his answer, I have a more dry'er approach and in es6 for those interested:

    class RadioExample extends React.Component {
      constructor(props) {
        super(props);
    
        this.state = {
          selectedRadio: 'public'
        };
      }
    
      handleRadioChange = (event) => {
        this.setState({
          selectedRadio: event.currentTarget.value
        })
      };
    
      render() {
        return (
          
    ) } }

    except this one would have a default checked value.

提交回复
热议问题