我正在尝试从App组件内的导出函数中使用this.state
。
绑定方法不起作用。有什么想法吗?
我尝试过:
内部error-handler.js
export function errorHandler() {
console.log(this.state);
}
在App.js内部
...
import { errorHandler } from '../../helpers/error-handler';
class App extends React.Component {
constructor(props) {
super(props);
this.errorHandler = errorHandler.bind(this);
}
...
尝试在App.js中运行errorHandler()的结果:
"Cannot read property 'bind' of undefined"
谢谢您的帮助。