当传递 console.log 时 Antd Table onChange 事件不起作用

Antd Table onChange event not working when console.log is passed

当 console.log 作为事件处理程序传递给 table 的 onChange 时,不会触发该事件。

<Table
    rowKey={(record) => record.id}
    columns={columns}
    dataSource={getData(page)}
    pagination={{ current: page, total: 100, pageSize: 20 }}
    onChange={console.log}
  />

但是当 console.log 的函数作为参数传递时事件会触发。

<Table
    rowKey={(record) => record.id}
    columns={columns}
    dataSource={getData(page)}
    pagination={{ current: page, total: 100, pageSize: 20 }}
    onChange={(...args) => console.log(...args)}
  />

知道为什么会这样吗?

示例代码:https://codesandbox.io/s/blissful-wescoff-fzm4y?file=/src/App.js

console.log 是一个函数,因此要调用它,您必须像调用其他函数一样添加 () 并为其提供参数。

onChange={console.log} 时,您从 React 指向 disabledLog。 当 onChange() 被调用时,事件 React 有 reenableLogs() 但你仍然指向 disabledLog,这将不会向控制台记录任何内容。

当通过 (...args) => console.log(...args) 时,您已创建到 console 的关闭点。

https://github.com/facebook/react/blob/HEAD/packages/shared/ConsolePatchingDev.js