Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs React事件处理程序上的控制台日志语句导致合成事件警告_Reactjs - Fatal编程技术网

Reactjs React事件处理程序上的控制台日志语句导致合成事件警告

Reactjs React事件处理程序上的控制台日志语句导致合成事件警告,reactjs,Reactjs,代码沙箱: 这是一些非常直接的代码: 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.nam

代码沙箱:

这是一些非常直接的代码:

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>You're trying to 
console.log()
an asynchronous synthetic event that is removed by the time the
callback
is executed. If you wish to to persist the event, then use
event.persist()
.

Using
event.persist()
, you can see all of the
event
properties:

ispatchConfig: Object
_targetInst: FiberNode
nativeEvent: InputEvent
type: "change"
target: <input name="value1" value="this is form a1"></input>
currentTarget: null
eventPhase: 3
bubbles: true
cancelable: false
timeStamp: 2926.915000000008
defaultPrevented: false
isTrusted: true
isDefaultPrevented: function () {}
isPropagationStopped: function () {}
_dispatchListeners: null
_dispatchInstances: null
isPersistent: function () {}
<constructor>: "SyntheticEvent"
constform=({Form,updateForm})=>{
常量handleChange=(事件、值)=>{
console.log(事件、值);
日志(event.target.name、event.target.value);
const newForm={……form,{[event.target.name]:event.target.value};
updateForm(newForm);
};
返回(
handleChange(事件)}
/>
);
};
const Form1=连接(
state=>({form:state.form1}),
dispatch=>({updateForm:newForm=>dispatch(updateFormOne(newForm))})
)(表格);
函数Home(){
返回(

您正在尝试
console.log()
执行
回调时删除的异步合成事件。如果希望持久化事件,请使用
event.persist()

使用
event.persist()
,您可以看到所有
事件的属性:

const handleChange = ({ target: { value, name } }) => {
    console.log(name, value);

    const newForm = { ...form, [name]: value };
    updateForm(newForm);
  };