【发布时间】:2019-03-18 06:51:38
【问题描述】:
我想从 webViewEventHandlers.js 中的 export const 类调用 ComposeBox.js 中的 handleSend 函数
ComposeBox.js
class ComposeBox extends PureComponent<Props, State> {
handleSend = () => {
const { dispatch } = this.props;
const { message } = this.state;
dispatch(addToOutbox(this.getDestinationNarrow(), message));
this.setMessageInputValue('');
};
export default connect((state: GlobalState, props) => ({
auth: getAuth(state),
}))(ComposeBox);
webViewEventHandlers.js
import ComposeBox from '../compose/ComposeBox';
export const handleMessageListEvent = () => {
case 'wizrep':
ComposeBox.handleSend();
break;
我收到以下错误
【问题讨论】:
-
this的可能重复
-
谢谢兄弟,但它只适用于静态函数。
-
我有点明白你想做什么。但请记住一件事。如果你想调用一个类的函数,你需要一个它的实例。例如
class Foo{function method(){//do smth}} class Boo { function meth(){ var a = new Foo(); a.method();}} -
我试图实现你的例子
case 'wizrep': var test = new ComposeBox(); test.handleSend(); break;Cannot read property 'store' of undefined -
yes redux 我猜会导致这个错误。我认为您最好找到解决问题的新方法。
标签: reactjs react-native