简体   繁体   中英

Calling an action to update local storage (without API call) - redux persist, react native

I am trying to dispatch an action in redux sagas to add an id to a local store:

import { call, takeEvery } from 'redux-saga/effects';

import { BENEFITS } from '../actions/types';


function* addBenefitIdToViewedList(action){
    const id = action.payload.isClaimable? 'c'+ action.payload.id : 's'+action.payload.id;
    console.log(id)
    console.log(action)

    console.log(yield call({type: BENEFITS.VIEWED_LIST.ADD, rootAction:action}));
  }

  export default function*() {
    yield takeEvery(BENEFITS.VIEWED_LIST.POST, addBenefitIdToViewedList);
  }

I think the problem is the "yield call" - should I use sth different?

When I debug it, the BENEFITS.VIEWED_LIST.POST is called and the id and action is printed accordingly. However, the BENEFITS.VIEWED_LIST.ADD is not called. I need to call, so that reducer can update the store.

Any ideas? Thanks for help!

If you want to schedule the dispatching of an action to the store you need to use put as such: yield put(action) instead of call that just calls a function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM