Redux &을 사용하여 API에서 데이터를로드합니다. 데이터를 성공적으로 가져 와서 상태에 적용 했음에도 불구하고 오류가 발생합니다.Redux 정의되지 않은 'payload'속성을 읽을 수 없습니다.
"Uncaught TypeError : 'payload'of undefined"속성을 읽을 수 없습니다. 이는 콘솔에서 FETCH_PRODUCT_LISTINGS_PENDING 활동 유형 다음에 발생합니다.
import Config from '../../../Config.js';
import store from '../../../store.js';
import axios from 'axios';
export function fetchProductListings() {
store.dispatch({
type: "FETCH_PRODUCT_LISTINGS",
payload: axios.get(Config.getConfigAPIUrl() + '/cartel/products')
})
}
어떤 도움이 appre 다음과 같습니다
import React from 'react';
import { connect } from 'react-redux';
import store from '../../../store';
import * as ProductListingActions from '../actions/ProductListingActions';
@connect((store) => {
return {
productListing: store.productListing.products
}
})
export default class ProductListingContainer extends React.Component {
constructor(data) {
super();
this.props = data;
this.props.dispatch(ProductListingActions.fetchProductListings());
}
render() {
return <div></div>;
}
}
감속기 :
import CookieHandler from '../../../modules/CookieHandler';
const cookieHandler = new CookieHandler;
export default function reducer(
state = {
products: [],
fetching: false,
fetched: false,
error: null
}, action) {
switch(action.type) {
case "FETCH_PRODUCT_LISTINGS_PENDING":
return {
...state,
fetching: true,
}
break;
case "FETCH_PRODUCT_LISTINGS_REJECTED":
return {
...state,
fetching: false,
error: action.payload
}
break;
case "FETCH_PRODUCT_LISTINGS_FULFILLED":
return {
...state,
fetching: false,
fetched: true,
products: action.payload.data.default
}
break;
}
return state;
}
작업
는 구성 요소 반응 ciated
완벽하고 매력적인 작품! 고마워요 – DorianHuxley
참고 - 나는 이미 redux - 썽크를 사용하고 있지만, 팁 주셔서 감사합니다 :) – DorianHuxley