フルコード:https://github.com/kenpeter/test_infinite_scroll_1還元剤の初期状態に非同期値の戻り値を割り当てる方法はありますか?
私は還元剤を持っています。それはlist
と呼ばれる支柱を持っています。 createList([], 0)
はリモートAPIを呼び出してデータを取得した後、list
に割り当てます。
./reducers/loadMore.js
import { MORE_LIST } from "../actions/types";
import { createList } from "../utils/func";
const initState = {
list: createList([], 0) // <--------------------
};
// able to fire
export default function list(state = initState, action = {}) {
switch(action.type) {
case MORE_LIST:
return {
list: action.list,
}
default:
return state;
}
}
./utils/func.js
import _ from 'lodash';
import axios from "axios";
// clone the array
export function createList(arr=[],start=0) {
let apiUrl = "http://www.mangaeden.com/api/list/0?p=0";
return axios.get(apiUrl).then((obj) => {
let arr = obj.data.manga; // array of obj
//console.log("--- start ---");
//console.log(arr);
return arr;
});
}
私はfunction createList(arr=[],start=0)
を持っている問題は、 arr
は、リモートAPIからデータを持っているが、それはありますlist
に戻る./reducers/loadMore.js