0

firebase authリスナーを使用して、ドキュメントごとにlogIn関数をディスパッチしようとしています。しかし、リスナーを使用して、私の状態に移入するための還元アクションをトリガーしたいと思います。ReactネイティブでFirebase authからReduxアクションをディスパッチする方法

私がしようとすると、次のコードを実行すると、成功しfirebaseを使用してログインすると、それは「未定義の 『ログイン』プロパティを読み取ることができませんで失敗。

HALPください

class RootApp extends Component { 
 
    componentWillMount() { 
 
     // Listen for Auth Changes 
 
     firebase.auth().onAuthStateChanged(function(user) { 
 
      if (user) { 
 
       this.props.logIn(
 
        uid, 
 
        displayName, 
 
        photoURL, 
 
        providerId, 
 
        email, 
 
        emailVerified 
 
       ); 
 
       // User is signed in. 
 
      } else { 
 
       console.log("Not logged in"); 
 
       // No user is signed in. 
 
      } 
 
     }); 
 
    } 
 

 
    render() { 
 
     if (this.props.auth.checking == true) { 
 
      return (
 
       <ActivityIndicator 
 
        animating={true} 
 
        style={styles.activityIndicator} 
 
        size="large" 
 
       /> 
 
      ); 
 
     } else if (this.props.auth.signedIn == true) { 
 
      return <SignedIn />; 
 
     } else { 
 
      return <SignedOut />; 
 
     } 
 
    } 
 
} 
 

 
const styles = StyleSheet.create({ 
 
    container: { 
 
     flex: 1, 
 
     backgroundColor: "#fff", 
 
     alignItems: "center", 
 
     justifyContent: "center", 
 
     fontSize: 96 
 
    }, 
 
    activityIndicator: { 
 
     flex: 1, 
 
     justifyContent: "center", 
 
     alignItems: "center", 
 
     height: 80 
 
    } 
 
}); 
 

 
const mapStateToProps = state => { 
 
    return { 
 
     auth: state.auth 
 
    }; 
 
}; 
 

 
const mapDispatchToProps = dispatch => { 
 
    return { 
 
     logIn: (
 
      uid, 
 
      displayName, 
 
      photoURL, 
 
      providerId, 
 
      email, 
 
      emailVerified 
 
     ) => { 
 
      dispatch(
 
       logIn(
 
        uid, 
 
        displayName, 
 
        photoURL, 
 
        providerId, 
 
        email, 
 
        emailVerified 
 
       ) 
 
      ); 
 
     } 
 
    }; 
 
}; 
 

 
export default connect(mapStateToProps, mapDispatchToProps)(RootApp);

答えて

0

これを打つ他の人にとって答えはfirebaseサンプルのリスナー関数を太い矢印関数に変換することでした。例で使用されていた古い関数が自分自身の 'this'に束縛されていたからです。ありません。

ので、この:

firebase.auth()に変更するonAuthStateChanged(関数(ユーザ){

必要があります。

firebase.auth()onAuthStateChanged(ユーザー=> {

関連する問題