1

When I want to chain Redux actions, I use callbacks, but I want a clean solution without using callbacks. I don't want to use this methodology:

export const onClick = () => fetchRequest1(id, fetchRequest2)
export const fetchRequest1 = (id, callback) => {
  ...
  // on success
  call(fetchRequest2 , data)
}

Adam
  • 3,829
  • 1
  • 21
  • 31
khaliloos benk
  • 67
  • 3
  • 11
  • Where is your redux-saga code? – Ori Drori Feb 06 '21 at 12:30
  • Does this answer your question? [How to achieve callbacks in Redux-Saga?](https://stackoverflow.com/questions/41076600/how-to-achieve-callbacks-in-redux-saga) – Adam Feb 12 '21 at 01:27

2 Answers2

0

You could handle this case by using async await syntax

export const brand_fetchAll = () => {
return async dispatch => {

try{
  const res=await  fetch(apiURL+'brand')
  const data= await res.json()
    dispatch({ type: 'BRAND_STORE_ALL',content})
    }  catch (error) {
    alert(error.message)
    }
}}
0

You can use Actions Creator to create callback-capability standardized actions

npm install actions-creator
import actionsCreator from "actions-creator"
const my_callback = () => {
    console.log("Hello, I am callback!!!")
}
const callbackable_action = actionsCreator.CALLBACKABLE.EXAMPLE(1, 2, 3, my_callback)
console.log(callbackable_action)
//      {
//          type: "CALLBACKABLE/EXAMPLE",
//          args: [1, 2, 3],
//          cb: f() my_callback,
//          _index: 1
//      }
callbackable_action.cb()
//      "Hello, I am callback!!!"

see: Actions Creator