For example I have the following JSX. the name and id attributes are ignored when formHtml is rendered to the DOM. Where am I going wrong? *Please keep in mind the html I am rendering is not meant to be a controlled component or what have you. I'm also aware that "for" attribute should be "htmlFor" in React, but for reasons I need it to be "for" as the rendered html will be exported for the user eventually and is not intended to be used by the React application. Any tips on how to remove error messages about htmlFor would be greatly appreciated! :)
EDIT: So turns out I'm a bit silly and el.value simply didn't exist. I've changed it to a value that does exist and now all is working fine. If anyone has a tip on removing the htmlFor warning though that would be awesome. Thank you to the commenter who prompted me to realise my mistake.
const formHtml = form.map((el) => {
let element = null
let classes = 'block'
if (el.element === 'select') {
const optionTags = el.optionValues.map((el, index) => {
return (
<option value={el} key={index}>
{el}
</option>
)
})
element = <select name={el.value}>{optionTags}</select>
} else {
if (el.type === 'checkbox' || el.type === 'radio') {
classes = 'block flex-hori'
}
if (el.element === 'input') {
element = <input name={el.value} id={el.value} type={el.type}></input>
} else {
element = <el.element name={el.name} id={el.value}></el.element>
}
}
return (
<div className={classes} key={el.id}>
<label for={el.label}>{el.label}</label>
{element}
</div>
)
})