React / Redux:Action creator不能与redux-thunk一起使用

时间:2016-11-04 11:46:31

标签: reactjs redux middleware react-redux redux-thunk

我的React / Redux应用程序中有以下操作创建者,我正在尝试获取一些数据。为此,我使用superagent&终极版-的thunk。但是,虽然函数被调用(它确实记录(1) Called),但它不会进入thunk-part,因此(2) Called永远不会在控制台中打印出来。

export function fetchPosts () { //fetches headline, calls dispatchHeadline to dispatch the newly fetched headline
    console.log("(1) Called");
    return (dispatch) => {

        console.log("(2) Called");
        let url = "http://innovation-insight.dev/wp-json/wp/v2/posts";
        let blogposts = [];

        Request.get(url).then((response) =>{
            console.log("response3000:");
            console.log(response);

        //   for(var i=0; i< response.body.length; i++)
        //   {
        //     blogposts.push(response.body[i]);
        //     console.log(blogposts[i].title.rendered);
        //   }

        let currentPost = response.body[0];
        dispatch(dispatchPosts(currentPost));
    }).catch((error) => {
        console.log(error);
    });
    }
}

0 个答案:

没有答案