Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

256
Views
Error de mapa de React-redux TypeError: no se puede leer la propiedad 'mapa' de indefinido

Recibo el siguiente error en mi código ReactJS:

TypeError: no se puede leer la propiedad 'mapa' de indefinido

Esto se basa en el siguiente código:

 import React, { Component } from "react"; import { connect } from "react-redux"; import { ListGroup, ListGroupItem } from "reactstrap"; import { bindActionCreators } from "redux"; import * as categoryActions from "../../redux/actions/categoryActions"; class CategoryList extends Component { componentDidMount() { this.props.actions.getCategories(); } render() { return ( <div> <h3>Categories</h3> <ListGroup> {this.props.categories.map(category => ( <ListGroupItem key={category.id}> {category.categoryName} </ListGroupItem> ))} </ListGroup> <h5>The Category: {this.props.currentCategory.categoryName}</h5> </div> ); } } function mapStateToProps(state) { return { currentCategory: state.changeCategoryReducer, categories: state.CategoryListReducer, }; } function mapDispatchToProps(dispatch) { return { actions: { getCategories: bindActionCreators( categoryActions.getCategories, dispatch ), changeCategory: bindActionCreators( categoryActions.getCategories, dispatch ), }, }; } export default connect(mapStateToProps)(CategoryList);

No sé cómo puedo solucionar este error. ¿Puedes ayudarme por favor?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

antes de usar map() use una condición para verificar que el gancho tenga algún valor. Si no, la condición no funcionará y no se mostrará nada y no obtendrá ningún error.

about 4 years ago · Juan Pablo Isaza Report

0

Pruebe lo siguiente en su función de renderizado

 return ( <div> <h3>Categories</h3> <ListGroup> {this.props.categories && this.props.categories.map(category => ( <ListGroupItem key={category.id}> {category.categoryName} </ListGroupItem> ))} </ListGroup> <h5>The Category: {this.props.currentCategory.categoryName}</h5> </div> );
about 4 years ago · Juan Pablo Isaza Report

0

React intenta renderizar la interfaz de usuario incluso si los datos no están seguros o están vacíos. Debe simplificar la sintaxis de Javascript. ¿Por favor agregue ? en su método de renderizado .

 <ListGroup> {this.props.categories?.map(category => ( <ListGroupItem key={category.id}> {category.categoryName} </ListGroupItem> ))} </ListGroup>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!