これは、onBlurとonChangeの両方を使用し、状態の現在アクティブな入力要素を追跡するだけでこれを解決しました。
モジュールをリセットして新しいデフォルト値を再表示する方法がある場合は、それを正しいものとしてマークします。レンダリング機能で
state = {
inFocusIndex: null,
inFocusDisplayOrder: 0,
};
onOrderBlur() {
const productRow = this.props.products[this.state.inFocusIndex];
const oldDisplayORder = productRow.displayOrder;
// This can change all the display order values in the products array
this.props.updateDisplayOrder(
this.props.groupId,
productRow.productGroupLinkId,
oldDisplayORder,
this.state.inFocusDisplayOrder
);
this.setState({ inFocusIndex: null });
}
onOrderChanged(index, event) {
this.setState({
inFocusIndex: index,
inFocusDisplayOrder: event.target.value,
});
}
:
{this.props.products.map((row, index) => {
return (
<input
type="text"
value={index === this.state.inFocusIndex ? this.state.inFocusDisplayOrder : row.displayOrder}
className={styles.displayOrder}
onChange={this.onOrderChanged.bind(this, index)}
onBlur={this.onOrderBlur.bind(this)} />
);
})}
はなぜ代わりにdefaultValue' 'の 'の値を' を使用していませんか?あなたはあなたの入力値をコントロールすることができます。あなたが[制御されていないコンポーネント](https://facebook.github.io/react/docs/forms.html#uncontrolled-components)を取得したため、 'defaultValue'を使うのは悪い習慣です。 –
@DamienLeroux私はこの問題について説明しました。値を変更すると、レンダー順がすぐに変更されます。 – SystemicPlural
@ SystemicPluralただし、ドキュメントに記載されているように、defaultValueは初期レンダリングにのみ使用する必要があります。初期レンダリングの後、値を使用して制御されたコンポーネントとして更新する必要があります。 – erichardson30