Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot convert undefined or null to object #154

Closed
fwh1990 opened this issue Mar 2, 2018 · 4 comments
Closed

Cannot convert undefined or null to object #154

fwh1990 opened this issue Mar 2, 2018 · 4 comments

Comments

@fwh1990
Copy link

fwh1990 commented Mar 2, 2018

从2.0.6升级到2.0.7用不了,错误定位到 componentDidUpdate 的 prevProps.onEvents。错误是从react-dom发出来的,没啥卵用。回滚到2.0.6恢复正常。

  • webpack: 3.11
  • babel: 7.0-beta40
  • react: 16
@hustcc
Copy link
Owner

hustcc commented Mar 2, 2018

可以看下你使用组件的代码吗?是因为 onEvents 为 null 吗?

@fwh1990
Copy link
Author

fwh1990 commented Mar 2, 2018

onEvents没有传过,也没有用过,错误提示给你吧:

Uncaught TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at ProxyComponent.componentDidUpdate (core.js:139)
    at commitLifeCycles (react-dom.development.js:8778)
    at commitAllLifeCycles (react-dom.development.js:9946)
    ...

@hustcc
Copy link
Owner

hustcc commented Mar 2, 2018

理论上,onEvents 如果是 undefined 的话,会自动转成 {}。

现在的情况应该是 onEvents 传了 null 了。

Object.keys(null);

上面的代码就会报 Uncaught TypeError: Cannot convert undefined or null to object 错误。


可以看一下你具体的代码片段吗?

@hustcc hustcc closed this as completed in caa31b4 Mar 2, 2018
@fwh1990
Copy link
Author

fwh1990 commented Mar 2, 2018

已解决。因为继承ReactEchartsCore,然后在子类增加自定义的defaultProps。正确做法是

Object.assign({}, ReactEchartsCore.defaultProps, ...);

@hustcc hustcc changed the title 2.0.7bug Cannot convert undefined or null to object Mar 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants