所以我制作了一个 react 应用程序,并且有一个屏幕,标题右侧有一个按钮。问题是点击时会崩溃。这是 react 组件内的代码(位于构造函数方法的正上方):
static navigationOptions = {
headerRight: <Ionicons style={{marginRight: 15}} name={prefix + 'power'}
color={colors.app_secondary_color} size={30} onPress={() => this.signout()}/>
}
这是错误:
_this3.signout is not a function. (In '_this3.signout()', '_this3.signout' is undefined)
onPress
ProfileView.js:25:80
我认为这个引用文献还没有达到那么远?
最佳答案
没有 this.signout
因为 navigationOptions
是静态的。您可以通过将按钮提取到不同的组件并将其连接到 redux 存储来实现您想要的目的,然后在 Press 上调度注销操作
关于javascript - React 导航 - 堆栈导航按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46835658/