コンポーネントが搭載されたときに、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);
私のアクション・ファイルは、次のようになります
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)() ; 'それを呼び出す。 –