How to use radio buttons in ReactJS?

前端 未结 10 2134
再見小時候
再見小時候 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:32

    Here is a simplest way of implementing radio buttons in react js.

    class App extends React.Component {
      
      setGender(event) {
        console.log(event.target.value);
      }
      
      render() {
        return ( 
          
    Male Female
    ) } } ReactDOM.render(, document.getElementById('app'));
    
    
    

    Edited

    You can use arrow function instead of binding. Replace the above code as

    this.setGender(event)}>

    For a default value use defaultChecked, like this

     Male
    

提交回复
热议问题