代码沙箱在这里:https : //codesandbox.io/s/0olpzq7n3n
这是一些非常直接的代码:
const Form = ({ form, updateForm }) => {
const handleChange = (event, value) => {
console.log(event, value);
console.log(event.target.name, event.target.value);
const newForm = { ...form, ...{ [event.target.name]: event.target.value } };
updateForm(newForm);
};
return (
<form>
<input
name="value1"
value={form.value1}
onChange={event => handleChange(event)}
/>
</form>
);
};
const Form1 = connect(
state => ({ form: state.form1 }),
dispatch => ({ updateForm: newForm => dispatch(updateFormOne(newForm)) })
)(Form);
function Home() {
return (
<div>
<h2>👋 Welcome to the Home route</h2>
<Form1 />
</div>
);
}
如果您在这种情况下编辑表单输入,它会给出以下警告:
Warning: This synthetic event is reused for performance reasons. If you're seeing this, you're accessing the property `nativeEvent` on a released/nullified synthetic event. This is set to null. If you must keep the original synthetic event around, use event.persist(). See (shortend URL that StackOverflow doesn't like).
如果我删除这些控制台日志语句,警告就会消失。
这里发生了什么事?