Why use a contractile or saxon saga for sampling?

I continue to read that for handling side effects I have to use the reduction-thunk or redux saga. Why not just use action creators to submit multiple actions:

function loadProductActionCreator(dispatch) {
  dispatch({
    type: 'load_product',
  })
  fetch('api/product').then(
    function (r) {
      return r.json();
    }
  )
  .then(function (res) {
    dispatch({
      type: 'loaded_product',
      data: res
    })
  })
}

I tried this and it worked ( full code ). Therefore, I suggest that there should be some inconvenience that I do not know about.

+4
source share
2 answers

You code is similar to what thunk does.

redux . . fetch, , , .

. , actionsx.

?

, , , .

redux-saga:

  • , ,

    {
      type: 'FETCH_POSTS',
      params: {
        category: 'programming'
      }
    }
    
  • , , API

:

  • ( )
  • "dummy" API
  • reducex dev
  • debounce, throttle , decux-thunk
  • ( /, )
  • .

( ) redux-thunk, , . redux-saga, .

+4

. , , (. redux doc ).

, ,

+1

Source: https://habr.com/ru/post/1663474/


All Articles