2

I'm Learning reactjs from some courses/videos and so far I'm really bad at it and I checked a few times and i couldn't see the error. So I can't understand this error. Can somebody help please?? this is my code:

import React, { useState } from 'react';
import CartSummary from './CartSummary'


import CategoryList from './CategoryList'
import ProductList from './ProductList'
import {
  Collapse,
  Navbar,
  NavbarToggler,
  NavbarBrand,
  Nav,
  NavItem,
  NavLink,
  UncontrolledDropdown,
  DropdownToggle,
  DropdownMenu,
  DropdownItem,
  NavbarText
} from 'reactstrap';

const Navi = (props) => {
  const [isOpen, setIsOpen] = useState(false);

  const toggle = () => setIsOpen(!isOpen);

  return (
    <div>
      <Navbar color="light" light expand="md">
        <NavbarBrand href="/">Nortwind App</NavbarBrand>
        <NavbarToggler onClick={toggle} />
        <Collapse isOpen={isOpen} navbar>
          <Nav className="mr-auto" navbar>
            <NavItem>
              <NavLink href="/components/">Components</NavLink>
            </NavItem>
            <NavItem>
              <NavLink href="https://github.com/reactstrap/reactstrap">GitHub</NavLink>
            </NavItem>
            <CartSummary cart={this.props.cart}></CartSummary>
          </Nav>
          <NavbarText>Simple Text</NavbarText>
        </Collapse>
      </Navbar>
    </div>
  );
}

export default Navi;

this is the Error:

 37 |     <NavItem>
  38 |       <NavLink href="https://github.com/reactstrap/reactstrap">GitHub</NavLink>
  39 |     </NavItem>
> 40 |     <CartSummary cart={this.props.cart}></CartSummary>
     | ^  41 |   </Nav>
  42 |   <NavbarText>Simple Text</NavbarText>
  43 | </Collapse>

So can someone help me please?

2
  • 2
    you don't need the this keyword here. It is usually used with class based components. You are using a react functional component. Commented Aug 21, 2020 at 10:45
  • What do you think this is referring to here? props has been declared as a parameter of your fat arrow function... There is no this. Commented Aug 21, 2020 at 10:46

2 Answers 2

2

problem is in this line

<CartSummary cart={this.props.cart}></CartSummary>

Here you need to write

<CartSummary cart={props.cart}></CartSummary> as you use functional component

Sign up to request clarification or add additional context in comments.

Comments

1

You don't have to use keyword this here, because its functional component.

Btw I recommend you to read about prop-types library. It helps you to define default props to avoid undefined props errors.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.