pass multiple values to redux saga call

Viewed 2905

I need to pass 2 values to a post request. I have written the call as such

       const { phoneNumber, code } = params;

        yield call(
          apiCall,
          Generic.loginSms,
          actions.loginSmsLink(phoneNumber, code)
        );

the action is as such.

        export const loginSmsLink = createAction(
          ActionTypes.SMS_CODE_LOGIN,
          phoneNumber => ({ phoneNumber }),
          code => ({ code })
        );

the request:

       loginSms: apiCall(({phoneNumber, code}) => ({
         method: 'POST',
         url: '/login',
         data: {
           loginAuthenticationToken: {
            '@type': 'sms',
            phoneNumber,
            code
           }
          }
        })),

The request is only accepting the first param of phoneNumber.

2 Answers

I believe the problem is because you're passing an object as the argument to your function. If your argument were to accept multiple parameters, this should work:

loginSms: apiCall((phoneNumber, code) => ({
  method: 'POST',
  url: '/login',
  data: {
    loginAuthenticationToken: {
      '@type': 'sms',
      phoneNumber,
      code
    }
  }
})),

If you read the Redux Saga documentation you can see call takes a function and an array of arguments:

call(fn, ...args)

You need to pass multiple arguments in an array.

Related