0
ジェネリック入力を使用してフォームを作成しようとしていますが、入力するたびにこの入力のフォーカスを失い、再度クリックしなければなりません。リアクションフォームが更新に集中しなくなる
handleChange(propertyName, event) {
const contact = this.state.contact;
contact[propertyName] = event.target.value;
this.setState({ contact: contact });
}
render() {
const FormInput = (props) => {
return (
<label>
Name:
<input
type="text"
placeholder="Enter text"
onChange={event => this.handleChange(props.name, event)}
value={props.value}
/>
</label>
)
}
return (
<form>
<FormInput value={this.state.videoName} name="videoName" />
<FormInput value={this.state.title} name="title" />
</form>
);
};
handleChange関数は、setStateの前に突然変異しています。これは、不変であるとみなされるべきであるため、間違っています。 – Nath