탑재 할 때 redux 저장소에 항목 데이터를 채워야하는 컨테이너 구성 요소가 있는데 구성 요소는 올바르게 id
인 작업을 호출합니다 요청했다. 이 작업은 수행되지 않는 dispatch
함수를 반환하므로 데이터는 검색되지 않습니다.Redux-thunk 동작은 실행되지 않는 함수를 반환하므로 데이터를 가져 오지 않습니다.
내가 뭘 잘못하고 있니?
내 컨테이너 구성 요소는 이것이다 :
내 활동 파일은 다음과 같습니다import { connect } from "react-redux";
import React, { Component } from "react";
import fetchItem from "../actions/itemActions";
import ItemDetails from "../components/ItemDetails";
class ItemDetailsContainer extends Component {
state = {
item: null
};
componentDidMount() {
return fetchItem(this.props.match.params.number);
}
render() {
return <ItemDetails {...this.props} />;
}
}
const mapStateToProps = (state, props) => {
return {
item: state.item,
user_location: state.user_location
};
};
export default connect(mapStateToProps)(ItemDetailsContainer);
: fetchItem
를 호출 할 때
import * as actions from "../constants/constants";
import fetch from "isomorphic-fetch";
const itemDetailsRequest = id => {
return {
type: actions.FETCH_ITEM_REQUEST,
id,
receivedAt: Date.now()
};
};
const itemDetailsSuccess = (id, json) => {
return {
type: actions.FETCH_ITEM_SUCCESS,
items: json.map(child => child),
receivedAt: Date.now()
};
};
const itemDetailsFailure = (id, json) => {
return {
type: actions.FETCH_ITEM_FAILURE,
error: json.error,
receivedAt: Date.now()
};
};
const fetchItem = id => {
console.log(`returning dispatch function for item, id: ${id}`);
return function(dispatch) {
console.log("fetching Item: " + id);
dispatch(itemDetailsRequest(id));
fetch(`item.json?id=${id}`)
.then(
response => response.json(),
error => console.log("AN ERROR OCCURED.", error)
)
.then(json => {
dispatch(itemDetailsSuccess(id, json));
});
};
};
export default fetchItem;
는'fetchItem'는 함수가'시도 반환 fetchItem (this.props.match.params.number)() ; '그것을 호출합니다. –