如何从静态navigationOptions - react-navigation调用this.props

问题描述 投票:0回答:1

我试图在堆栈导航器的标题中的onPress按钮中调用handlelogout(),然后在handlelogout()中调用this.props.logout动作,它将调用导航减速器重置为登录屏幕.....但this.props.logout不会召集行动....没有任何反应

static navigationOptions = ({ navigation }) => {
    const { params } = navigation.state;
    console.log("navigation", navigation);

    return {
      title: "Profile List",
      gesturesEnabled: false,
      headerLeft: null,
      headerRight: <Button title={"Logout"} onPress={() => params.handlelogout && params.handlelogout({ state: navigation.state })} />
    }
  };

这是我的handlelogout函数

handlelogout(state) {
    console.log("in handlelogout", this.props.logout, state);
    this.props.logout;
  }

i am attaching the log i printed in the console

这里我将logout绑定到mapdispatchprops

function mapDispatchToProps(dispatch) {
  return bindActionCreators(ReduxActions, dispatch);
}
react-native react-navigation stack-navigator
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.