I have a number of fields which are produced from arrays dynamically and are bound to a redux state branch. The input value is correctly mapped to the state, then back to component. The problem is it loses focus, you have to re click the input element. I tried to work around this by auto focusing the last updated field, but it focuses at the beginning of the text so that you would write backwards. I looked for solutions to that problem but they all require working directly on the dom or using "onFocus="this.value=value" which as a jsx attribute will not work.
Is there something I'm doing wrong here? Why doesn't react remember the field to be focused automatically as it does with static jsx input elements?
Here is the code which produces the fields:
const renderFields = (fields, target) => {
if(!fields) return <div></div>
return fields.map(field => {
let input = []
if(field.type==="text") {
input.push(<input key={generateUID()} type="text" onChange={e=>onChange(field, e.target.value, target)} autoFocus={field.hasFocus} value={field.value} />)
} else if(field.type==="radio") {
let values = field.control.match(/\[(.+)\]/)[1].split(",")
input = values.map(value => {
return (<label key={generateUID()}><input name={field.id} onChange={e=>onChange(field, value, target)} type="radio" value={value} key={generateUID()} style={{display: "inline-block"}} /> {value}</label>)
})
}
return (
<div key={generateUID()}>
<label>{field.label}</label>
<br />
{input}
</div>
)
})
}
I appreciate any help