首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >React本机Redux离线API响应

React本机Redux离线API响应
EN

Stack Overflow用户
提问于 2019-02-21 16:31:32
回答 1查看 702关注 0票数 1

如何在redux-offline中查看我在reducer中的API响应。在我的代码下面,我在I can see my request data中的reducer中记录了我的操作。在reducer中如何提前记录我响应数据.thanks

我的代码在这里

action.js

代码语言:javascript
复制
 export const sample = (requestbodydata) => ({

          type: 'ACTION_CALL',
          payload: { requestbodydata },
          meta: {
            offline: {
              // the network action to execute:
              effect: { url: 'http://localhost:5000/api/v1/test/data', method: 'POST',  body: requestbodydata , headers: { 'content-type': 'application/x-www-form-urlencoded' } },
              // action to dispatch when effect succeeds:
              commit: { type: 'ACTION_CALL_COMMIT', meta: { requestbodydata } },
              // action to dispatch if network action fails permanently:
              rollback: { type: 'ACTION_CALL_ROLLBACK', meta: { requestbodydata } }
            }
          }
        });

reducer.js

代码语言:javascript
复制
export default function reducer(state = {}, action) {
    switch (action.type) {        
        case 'ACTION_CALL':
        console.log('get response'+JSON.stringify(action));

        case 'ACTION_CALL_COMMIT':
        console.log('ACTION_CALL_COMMIT')
        console.log('After commit response'+JSON.stringify(action));

        case 'ACTION_CALL_ROLLBACK':
        console.log('ACTION_CALL_ROLLBACK')


        default:
            return state
    }
}

store.js

代码语言:javascript
复制
    import { applyMiddleware, createStore, compose } from 'redux';
    import { offline } from '@redux-offline/redux-offline';
    import offlineConfig from '@redux-offline/redux-offline/lib/defaults';
    import reducer from './reducer';


const store = createStore(
  reducer,
  {},
  compose(
    applyMiddleware(thunk),
    offline(offlineConfig)
  )
);

export default store;
EN

回答 1

Stack Overflow用户

发布于 2021-03-09 16:23:38

https://github.com/redux-offline/redux-offline/issues/63提到,提交会自动将其action.payload设置为效果的响应。

也许这可以用作以下内容:

代码语言:javascript
复制
case ACTION_CALL_COMMIT: 
  console.log(action.payload);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54802487

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档