Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Type 'void[]' is not assignable to type 'ReactNode'

This code block is OK:

        let attributes = <>
        {
            props.filter.attributes?.map((data) => {
                return
                <div className="form-check">
                    <input className="form-check-input" type="radio" id={data.id.toString()} name={props.filter.name} value={data.name} onChange={props.changeHandler} />
                    <label className="form-check-label">{data.name}</label>
                </div>
            })
        }
    </>

But this code has the error Type 'void[]' is not assignable to type 'ReactNode'. The only change is to wrap the map function in a div:

    let attributes = <>
        <div className="row row-cols-5">
            {
                props.filter.attributes?.map((data) => {
                    return
                    <div className="form-check">
                        <input className="form-check-input" type="radio" id={data.id.toString()} name={props.filter.name} value={data.name} onChange={props.changeHandler} />
                        <label className="form-check-label">{data.name}</label>
                    </div>
                })
            }
           </div>
        </>

What do I need to do to the second example to eliminate the error?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I think your return should looks as follows

return (
  <div className="form-check">
    <input className="form-check-input" type="radio" id={data.id.toString()} name={props.filter.name} value={data.name} onChange={props.changeHandler} />
    <label className="form-check-label">{data.name}</label>
  </div>
);

So the HTML should be wrapped into brackets. Otherwise, you actually have it as unreachable code and your function looks like simple

return;
// Some unreachable html here
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading