Reactjs 反应本机导航摆脱构造函数?
在Reactjs 反应本机导航摆脱构造函数?,reactjs,react-native,react-native-navigation,Reactjs,React Native,React Native Navigation,在react native navigation(而不是react navigation)中,示例显示 constructor(props) { super(props); Navigation.events().bindComponent(this); this.state = { text: 'nothing yet' }; } 在这种情况下,有没有办法摆脱构造函数?在构造函数中基本上有三件事在进行-调用超类构造函数、调用导航.events().bindCompon
react native navigation
(而不是react navigation
)中,示例显示
constructor(props) {
super(props);
Navigation.events().bindComponent(this);
this.state = {
text: 'nothing yet'
};
}
在这种情况下,有没有办法摆脱构造函数?在构造函数中基本上有三件事在进行-调用超类构造函数、调用
导航.events().bindComponent
,以及初始状态
如果没有构造函数,仍然会调用超级
构造函数,并且可以将状态初始化移到外部,如下所示:
state = {
text: 'nothing yet'
};
但是,无论何时在没有构造函数的情况下创建类的实例,都没有调用Navigation.events().bindComponent
的好方法。所以如果你需要调用这个函数,你需要一个构造函数