ZhangMYihua / lesson-12

We have added redux to our application so we can leverage all the benefits that come with uni-directional data flow. Instead of the prop drilling we would have to do in order to pass our new user object down deeper into our component trees from our app, we can now just connect those components directly to our redux store where we store all our data.
6 stars 75 forks source link

Facing error please resolve #24

Open rahul8798 opened 3 years ago

rahul8798 commented 3 years ago

import React from "react"; import "./App.css"; import HomePage from "./pages/homepage/homepage-component"; import { Switch, Route } from "react-router-dom"; import ShopPage from "./pages/shop/shop.component"; import Header from "./components/header/header.component"; import SignInAndSignUpPage from "./pages/sign-in-and-sign-up/sign-in-and-sign-up.component"; import { auth, createUserProfileDocument } from "./firebase/firebase.utils"; import { connect } from "react-redux"; import { setCurrentUser } from "./redux/user/user.actions";

class App extends React.Component { unsubscribeFromAuth = null;

componentDidMount() { const { setCurrentUser } = this.props;

this.unsubscribeFromAuth = auth.onAuthStateChanged(async (userAuth) => {
  if (userAuth) {
    const userRef = await createUserProfileDocument(userAuth);

    userRef.onSnapshot((snapShot) => {
      setCurrentUser({
        id: snapShot.id,
        ...snapShot.data(),
      });
    }); 
  }
  setCurrentUser(userAuth);
});

}

componentWillUnmount() { this.unsubscribeFromAuth(); }

render() { return (

);

} } const mapDispatchToProps = dispatch => ({ setCurrentUser: user => dispatch(setCurrentUser(user)) });

export default connect(null, mapDispatchToProps)(App);

Unhandled Rejection (TypeError): Object(...) is not a function in this line of code setCurrentUser: user => dispatch(setCurrentUser(user))

please help. i cannot find any help after searching in stackoverflow. @ZhangMYihua please help I am unable to proceed further in your course.

atg05 commented 2 years ago

Hello @rahul8798 , I have worked on this project. Share your errors with me so i can help you..