I have the following code in my component. It will get called when I update certain things, thereby replacing a bunch of things in the UI. Everything is updating EXCEPT the value of the input as seen by the user.
let input = {
id: 'discount-' + geo + '-' + segment,
value: percentage,
disabled: applyToAll,
placeholder: '0.00'
};
cells.push(
<td key={'cell-' + geo + '-' + segment} className=discount-segment cfix>
<Text {...input} />
</td>
);
This is what <Text>
returns, with things removed for clarity
return (
<div className={containerClasses.join(' ')} id={'field-container-' + id}>
{label}
<input
autoComplete=off
type=text
id={id}
ref=input
{...extraProps}
name={id}
className={classes.join(' ')}
defaultValue={this.props.value}
onChange={this.props.onChange}
/>
</div>
);
Everything renders fine. Let's say the percentage
value is 5
on start, it will show 5
in the field. I then do something else that updates percentage
to 50. (A console log will show the right number on re-render). However the value is only showing 5
in the UI still. I am using defaultValue
on the input field, but I figure that should be changing as the whole thing re-renders from parent.
Edit
Updated <Text>
to set value
instead of defaultValue
. However then I need to use state
to update the value when user types. Then when I re-render, I'm sending in new props with proper value, but of course props isn't updated. Catch-22 for me.