How to use radio buttons in ReactJS?

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

    Just an idea here: when it comes to radio inputs in React, I usually render all of them in a different way that was mentionned in the previous answers.

    If this could help anyone who needs to render plenty of radio buttons:

    import React from "react"
    import ReactDOM from "react-dom"
    
    // This Component should obviously be a class if you want it to work ;)
    
    const RadioInputs = (props) => {
      /*
        [[Label, associated value], ...]
      */
      
      const inputs = [["Male", "M"], ["Female", "F"], ["Other", "O"]]
      
      return (
        
    { inputs.map(([text, value], i) => (
    { text }
    )) }
    ) } ReactDOM.render( , document.getElementById("root") )
    
    
    
    

提交回复
热议问题