4

I have a simple saga. The Idea is to listen the action REQUESTS_OWNERSHIP_EDIT to be dispatched from the store and run submit submitOwnerships(ownerships) that is supposed to submit the ownership params to the server. I'm confused about how to get the ownerships value in the function dispatched from the saga.

Here it is my code:

// 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,
  };
}

I'm sure I'm missing something.

erikvold
  • 15,988
  • 11
  • 54
  • 98
TWONEKSONE
  • 3,918
  • 3
  • 19
  • 26

1 Answers1

3

The submitOwnereship saga gets the action (the result of editOwnerships function) and you can use an object destructuring to receive ownerships:

export function* submitOwnerships({ ownerships }) {
  ...
}
ischenkodv
  • 4,205
  • 2
  • 26
  • 34