1

In the redux-offline How to view my API response in the reducer. below my code i log my action in the reducer in the i can see my request data. In that reducer how to log my response data .thanks in advance

My code is here

action.js

 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

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

    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;
SATHEESH P
  • 389
  • 1
  • 3
  • 21

1 Answers1

0

https://github.com/redux-offline/redux-offline/issues/63 mentions that the commit automatically gets its action.payload set to the response of the effect.

Perhaps that could be used as the following:

case ACTION_CALL_COMMIT: 
  console.log(action.payload);
Simon
  • 621
  • 4
  • 21