0
votes

I'm trying to create a simple app with ReactJS, but I get this error and I don't know why.

enter image description here

This is my App.js.

import React from 'react';
import { connect } from 'react-redux';
import Category from './components/Category';
//import News from './components/Noticias';
import './App.css';

function App() {
  const { categories } = this.props;
  return (
    <div className="App">
      <Category categories={categories} />
      {/*<News />*/}
    </div>
  );
}

const mapStateToProps = state => {
  const { Categorias: {data: categories}} = state;

  return {
    categories,
  }
}

const mapDispatchToProps = dispatch => ({})

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

I'm working under v14.4.0 of node.js and this is my package.json for check react version, redux version, etc.

{
  "name": "noticias",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-redux": "^7.2.1",
    "react-scripts": "3.4.3",
    "redux": "^4.0.5",
    "redux-form": "^8.3.6"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

I'm checking but I don't find the error, can you help me?

1
You could just probably just use props instead of this.props. - BARNOWL
Function components don't access props on this. Please start with the basics: reactjs.org/tutorial/tutorial.html#function-components. - jonrsharpe
Oh, I had to pass props parameter in function and remove this. Thanks. - Alex Iglesias

1 Answers

0
votes

You might write this,

function App({ categories }) {
  // const { categories } = this.props;
  return (
    <div className="App">
      <Category categories={categories} />
      {/*<News />*/}
    </div>
  );
}