2017-12-21 7 views
0

スタックナビゲータのヘッダーにあるボタンのonPressでhandlelogout()を呼び出し、handlelogout()で私はthis.props.logoutアクションを呼び出していますログイン画面にリセットするには、ナビゲーション減速を呼び出します.....しかしthis.props.logoutがアクションを呼び出すdoesntの....何も静的なナビゲーションからthis.propsを呼び出す方法

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(state) { 
    console.log("in handlelogout", this.props.logout, state); 
    this.props.logout; 
    } 

i am attaching the log i printed in the console

012私handlelogout機能であるが起こりません

ここで私はあなたがその要素/クラスからあなたのログアウトを扱う別の要素内にボタンを配置しようとすることができます

function mapDispatchToProps(dispatch) { 
    return bindActionCreators(ReduxActions, dispatch); 
} 
+0

これが実際の問題であるのか疑問コードスニペットで間違っているのか分かりませんが、あなたは 'this.props.logout'メソッドを呼び出すことはありません。そのためには、 'this.props.logout()'で関数を呼び出す必要があります。 – jevakallio

+0

jevakallio this.props.logout(reduxactions)は、actioncreatorへのディスパッチアクションであり、ナビゲーションリデューサを呼び出します。 – Suv

答えて

0

をmapdispatchpropsするログアウトを結合しています。そのような

import ButtonForLogout from './test/buttonforlogout'; 

... 

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

    return { 
     title: "Profile List", 
     gesturesEnabled: false, 
     headerLeft: null, 
     headerRight: <ButtonForLogout /> 
    } 
    }; 

buttonforlogout.js

import React, { Component } from 'react'; 
import { View, Button } from 'react-native'; 
import { connect } from 'react-redux'; 
import { ReduxActions } from './youractions'; 

class ButtonForLogout extends Component { 

    render(){ 
    return(
     <View> 
     <Button title={"Logout"} onPress={this.props.logout} /> 
     </View> 
    ); 
    } 

} 

const mapStateToProps = state => ({}); 

export default connect(mapStateToProps, ReduxActions)(ButtonForLogout); 

何か。

関連する問題