将参数从根传奇传递到调度的动作

时间:2018-08-01 16:14:09

标签: javascript redux react-redux redux-saga react-boilerplate

我有一个简单的传奇。这个想法是听取要从商店调度的操作REQUESTS_OWNERSHIP_EDIT并运行应该将所有权参数提交给服务器的Submit submitOwnerships(ownerships)。 我对如何从传奇中分派的函数中获取ownerships值感到困惑。

这是我的代码:

// saga.js

import request from 'utils/request';

import { select, call, put, takeLatest } from 'redux-saga/effects';
import { editOwnerships } from './actions';
import { REQUESTS_OWNERSHIP_EDIT } from './constants';

export function* submitOwnerships(ownerships) {
  // I would like to have here ownerships equals to the parameter passed to my action. 
  const requestURL = 'http://localhost:3001/';
  try {
    const art = yield call(request, requestURL, { method: 'POST', body: ownerships });
    yield put(....);
  } catch (err) {
    yield put(....);
  }
}

export default function* ownershipEdit() {
  yield takeLatest(REQUESTS_OWNERSHIP_EDIT, submitOwnerships);
}


// actions.js

export function editOwnerships(ownerships) {
  return {
    type: REQUESTS_OWNERSHIP_EDIT,
    ownerships,
  };
}

我确定我缺少什么。

1 个答案:

答案 0 :(得分:2)

submitOwnereship传奇获得actioneditOwnerships函数的结果),您可以使用对象分解来接收ownerships

export function* submitOwnerships({ ownerships }) {
  ...
}