gpt4 book ai didi

javascript - 将参数从根 saga 传递到分派(dispatch)的操作

转载 作者:行者123 更新时间:2023-11-29 10:58:36 25 4
gpt4 key购买 nike

我有一个简单的故事。这个想法是监听要从商店发送的操作 REQUESTS_OWNERSHIP_EDIT 并运行 submit submitOwnerships(ownerships) 应该将所有权参数提交给服务器。我对如何在从 saga 调度的函数中获取 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,
};
}

我确定我遗漏了什么。

最佳答案

submitOwnereship saga 获取action(editOwnerships 函数的结果)并且您可以使用对象解构来接收所有权:

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

关于javascript - 将参数从根 saga 传递到分派(dispatch)的操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51637948/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com