reactjs - 如何在 redux saga 中发送 id?
问题描述
刚开始了解redux saga,如何在dispatch中传入我的数据?目前我的根传奇看起来像这样:
function* getData(id){
const data = yield fetch('https://jsonplaceholder.typicode.com/todos/'+id)
.then(response=>response.json())
yield put({type:"RECEIVED_DATA",json:data})
}
export default function* rootSaga(){
yield takeEvery("GET_DATA",getData)
}
如何在 getData 生成器中发送 id?
解决方案
您可以id
通过action
对象。像这样:
function* getData(action){ // fixed
const id = action.id // we get the `id` from the `action` object
const data = yield fetch('https://jsonplaceholder.typicode.com/todos/'+id)
.then(response=>response.json())
yield put({type:"RECEIVED_DATA",json:data})
}
export default function* rootSaga(){
yield takeEvery("GET_DATA",getData)
}
推荐阅读
- javascript - 模态javascript中的背景图像更改
- r - 编写一个返回 tibble 中变量类型的 R 函数
- c# - 如何使在通用组件中创建的属性可用于 blazor 中的渲染片段
- javascript - 必须手动刷新页面才能发出正确的警报
- reactjs - 导航链接不在 React Bootstrap 的导航栏中居中
- python - 如何将浮点数列表转换为整数。当那里有 NaN 值时!我从熊猫数据框中得到了这个列表,其中有一些空值
- java - Springboot JSP 提交表单,将数据作为 NULL 发送到 MYSQL 数据库;我该如何解决?
- unity3d - Dynamics Remote Assist 通过另一个统一应用程序(应用程序关闭)
- java - 将 bson 文档转换为字节数组 java
- qt - 文本:删除顶部的空白空间或获取其大小