Redux Saga-生成调用不返回数据

Redux Saga-生成调用不返回数据,redux,react-redux,redux-saga,Redux,React Redux,Redux Saga,嗨,我是新来Redux的,我目前正在使用一个功能,我试着去其他人的帖子,但对我没有太多帮助 问题 我成功地调用了我的API,但是由于某些原因,我发现它没有返回任何数据。当我在控制台上看到XHR选项卡时,我看到一个HTTP 200,并且有一个有效负载,但我没有看到任何错误,这使我不确定为什么没有看到任何返回的数据。我看到我的saga文件正在调用我的操作CREATE\u MATRIX\u请求,然后立即调用CREATE\u MATRIX\u SUCCESS。我真的不知道为什么会发生这种情况,任何帮助都

嗨,我是新来Redux的,我目前正在使用一个功能,我试着去其他人的帖子,但对我没有太多帮助

问题

我成功地调用了我的API,但是由于某些原因,我发现它没有返回任何数据。当我在控制台上看到XHR选项卡时,我看到一个HTTP 200,并且有一个有效负载,但我没有看到任何错误,这使我不确定为什么没有看到任何返回的数据。我看到我的saga文件正在调用我的操作CREATE\u MATRIX\u请求,然后立即调用CREATE\u MATRIX\u SUCCESS。我真的不知道为什么会发生这种情况,任何帮助都将不胜感激

actions.js

import {
  CREATE_MATRIX_REQUEST,
  CREATE_MATRIX_SUCCESS,
  CREATE_MATRIX_ERROR
} from './constants';



/**
 * Tells the app we want to create a matrix request
 */
export function createMatrixRequest(data) {
  return { type: CREATE_MATRIX_REQUEST, data};
}

/**
 * Tells the app the matrix request was succesfully made
 */
export function createMatrixSuccess(data) {
  return { type: CREATE_MATRIX_SUCCESS, data };
}

/**
 * Tells the app the matrix request failed
 */
export function createMatrixError(error) {
  return { type: CREATE_MATRIX_ERROR , error };
}
reducer.js

/*
 * The reducer takes care of state changes in our app through actions
 */
import { fromJS } from 'immutable';
import {
    CREATE_MATRIX_REQUEST,
    CREATE_MATRIX_SUCCESS,
    CREATE_MATRIX_ERROR
} from './constants';

// The initial application state
 const initialState = fromJS({
   success: false,
   error:''
 });

// Takes care of changing the application state
function createMatrixReducer(state = initialState, action) {
  switch (action.type) {
    case CREATE_MATRIX_REQUEST:
     return state;
    case CREATE_MATRIX_SUCCESS:
    console.log(action, 'This is a paylaod')
     return state.set('success', true);
    case CREATE_MATRIX_ERROR:
      return state.set('error', action.payload);
    default:
      return state;
  }
}


export default createMatrixReducer;
sagas.js

import { call, put } from 'redux-saga/effects';
import { takeEvery } from 'redux-saga/effects'
import { createMatrix } from './utils';
import { browserHistory } from 'react-router';

import { CREATE_MATRIX_REQUEST, CREATE_MATRIX_SUCCESS, CREATE_MATRIX_ERROR } from './constants';

export function* createMatrixSaga(action) {
   try {
      //Calls the API and sends payload
      const data = yield call(createMatrix, action.data);
      // We send an action that tells Redux we're sending a payload
      yield put({type: CREATE_MATRIX_SUCCESS, success: data});
      //Forward to /reports once actions is sent
      yield call(forwardTo, '/reports');

   } catch(error) {
     // We send an action that tells Redux we're sending an error
     yield put({type: CREATE_MATRIX_ERROR, error: error });
   }
}


function* watchFetchData() {
  // We send an action that tells Redux we're sending a request
    yield takeEvery(CREATE_MATRIX_REQUEST, createMatrixSaga);
}


export default [
  watchFetchData,
];

// Little helper function to abstract going to different pages
export function* forwardTo(location) {
  yield call(browserHistory.push, location);
}
utils.js

import axios from 'axios';
import cookie from 'react-cookie';


export function createMatrix({domain, kw}) {

  var token = cookie.load('token');
  var url = '';
  var keywords = kw;
  var encoded = encodeURI(keywords);
  var data = {
     key: token,
     keywords: encoded,
     analysisname: domain,
     country:1,
     location:null,
     trafficstats:false,
     use_majestic_api:false
  }
  axios.post(url, data).then((response) => {
      return response
  })
  .catch((error) => {
    throw error
  });
}


export default createMatrix;

如果存在有效负载,我认为问题在于axios post结果,例如:

import axios from 'axios';
import cookie from 'react-cookie';


export function createMatrix({domain, kw}) {

  var token = cookie.load('token');
  var url = '';
  var keywords = kw;
  var encoded = encodeURI(keywords);
  var data = {
     key: token,
     keywords: encoded,
     analysisname: domain,
     country:1,
     location:null,
     trafficstats:false,
     use_majestic_api:false
  }
  return axios.post(url, data).then((response) => {
      return response.data
  })
  .catch((error) => {
    throw error
  });
}


export default createMatrix;