我有一个简单的传奇。这个想法是听取要从商店调度的操作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,
};
}
我确定我缺少什么。
答案 0 :(得分:2)
submitOwnereship
传奇获得action
(editOwnerships
函数的结果),您可以使用对象分解来接收ownerships
:
export function* submitOwnerships({ ownerships }) {
...
}