Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facing issue while adding radio button in react - input is a void element tag and must neither have `children` nor use `dangerouslySetInnerHTML`

Tags:

reactjs

jsx

Input is a void element tag and must neither have children nor use dangerouslySetInnerHTML.

  render() {     let radioid = this.props.radioid;     return (       <div className="row">         {this.props.options.map(function(option) {           return (             <div key={radioid} className="column">               <input type="radio" name={radioid} value={option}>                 <label>{option}</label>               </input>             </div>           );          })}       </div>     );   } 

For example options is a list of elements like A, B, C, D

like image 951
Abdul Avatar asked Aug 19 '18 06:08

Abdul


People also ask

What is a void element tag?

Most HTML elements have a start tag and an end tag that indicate where the element begins and where it ends. There is a group of elements that are exceptions to this rule. These elements are called empty or void and only have a start tag since they can't contain any content.

Is Button void elements in HTML?

A void element is an element whose content model never allows it to have contents under any circumstances. Void elements can have attributes. The following is a complete list of the void elements in HTML : area , base , br , col , command , embed , hr , img , input , keygen , link , meta , param , source , track , wbr.


1 Answers

As per the error, the input tag should not have any children, take the label out of input closure tag

render() {     let radioid = this.props.radioid;     return (         <div className="row">         {this.props.options.map(function(option) {             return (             <div key={radioid} className="column">                 <label>{option}</label>                 <input type="radio" name={radioid} value={option}/>             </div>             );         })}         </div>     ); } 
like image 184
Anshul Bansal Avatar answered Sep 19 '22 16:09

Anshul Bansal