Coder Social home page Coder Social logo

zhangmyihua / lesson-12 Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 75.0 909 KB

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.

HTML 5.35% JavaScript 79.35% CSS 1.69% SCSS 13.61%

lesson-12's Issues

Facing error please resolve

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.

No SignOut link is shown

Despite the code is the same till now as Yihua explained, I always see SignIn instead of SignOut. The currentuser is always undefined in my console.log.

image

My Console
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.