React console 报错信息为什么这么少?

大部分的报错是这样的:
webpack:///./~/react/~/fbjs/lib/warning.js?:45 Warning: bind(): You are binding a component method to the component. React does this for you automatically in a high-performance way, so you

我不是想问这是什么错误, 而是想问, react 能否配置为更完善的错误信息, 比如至少告诉我这个 bing 警告出现在源代码哪一行.

阅读 4.8k
2 个回答

不能,运气好的话可以在调用栈中找到。

Dan Abramov吐槽过:

React is known for its relative lack of pitfalls and small API surface. This makes the few issues it has all the more frustrating, especially for the beginners.

I hope that these issues will be solved by more descriptive warnings in the next releases of React, but in the meantime here is something you, as a React beginner, should know in order to avoid hours of frustration.

另外针对这个报错信息,原因是在使用了React.createClass的情况下不需要给事件的handler额外bindthis

检查你的代码是否这样的 bind 使用。

<Component onClick={this.handleClick.bind(this)} />
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏