简体   繁体   English

在传递道具数据后,我无法在反应 js 中访问 json 的第二级

[英]I can't access the second level of a json after passing the data for props, in react js

I make a request with axios in a saga, which I receive in a component through the reduction in the mapStateToProps, if I go through the data in that component I can access any level but if I send it on props I can only access the first level of the json and on the second level I get Cannot read property 'route' of undefined我在传奇中向 axios 发出请求,我通过减少 mapStateToProps 在组件中收到该请求,如果我通过该组件中的数据 go 我可以访问任何级别,但如果我在道具上发送它我只能访问第一个json 的级别和第二级我得到无法读取未定义的属性“路线”

component where I trigger the action and receive the state, and I pass the props:我触发动作并接收 state 的组件,我传递了道具:

import React, { Component } from 'react';
import Aux from '../../hoc/Auxiliary';
import Products from '../../Components/ProductsSencillo/Products'
import { Grid } from 'styled-css-grid';
import { connect } from 'react-redux'
import { productComplete } from '../../redux/actions/productAction'
import reducerProduct from '../../redux/modules/reducers/productReducer'
import { bindActionCreators } from 'redux';

class ProductBuilder extends Component {
  componentDidMount() {
    this.props.handleListar();
  }
  render() {
    return (
      <Aux>
        <Grid columns="repeat(auto-fit,minmax(45px,1fr))">
          <Products products={this.props.state} />
        </Grid>
      </Aux>
    );
  }
}

const mapStateToProps = (state) => ({
  state: state.productReducer.productos.productos
})
const mapDispatchToProps = dispatch => ({
  handleListar: bindActionCreators(productComplete, dispatch),
})

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

component where I receive the props and the mappings:我收到道具和映射的组件:

import React, { Component } from 'react';
import Product from './Product/Product'
import { Cell } from 'styled-css-grid';

class Products extends Component {
  render() {
    return {
      this.props.products.map(pro => {
        return <Cell width={3}>< Product
          image={pro.imagen_principal.ruta}
          name={pro.nombre}
        />
        </Cell>
      })
    }
  }
}

export default Products;

error that throws me:抛出我的错误:

错误

API: API:

API 错误

When accessing "route" you have to first check if the value is present in the object that component receives.访问“路由”时,您必须首先检查该组件接收的 object 中是否存在该值。

Try this:尝试这个:

<Product image={pro.imagen_principal && pro.imagen_principal.ruta}/>

Hope this helps!希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React 将 props 传递给二级子级 - React Passing Props to Second-level Children 通过props反应JS Access Data JSON - React JS Access Data JSON via props 将数据传递到另一个组件后,为什么我不能在 React.js 中映射对象数组? - Why can't I map over an array of object in React.js after passing data to another component? React - 无法访问道具 - React - Can't access props 我无法在 React.js 中访问“this.props.match.params.id” - I can't access “this.props.match.params.id” in React.js 将道具数据传递到我只能通过路线访问的组件 - passing props data to component which i can only access with routes 反应js。 不能'获取未定义的值,用户的显示名称。 我已使用道具在此文件中使用用户 state 但它无法访问任何用户数据 - React js. Cant' get value of undefined, displayName of user. I have used props to use the user state in this file but it can't access any of user data 为什么我不能在react.js中更新道具? - Why can't I update props in react.js? 类型错误:无法读取未定义的属性“数据”-无法在 Reactjs 中访问超出特定级别的对象“道具” - TypeError: Cannot read property 'data' of undefined - can't access Object "props" beyond certain level in Reactjs 将{t}(从i18n-react)传递到无状态组件时,不能使用props - Can't use props when passing { t } (from i18n-react) to stateless component
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM