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.
You code is similar to what thunk does.
redux . . fetch, , , .
redux
fetch
. , actionsx.
?
, , , .
redux-saga:
redux-saga
, ,
{ type: 'FETCH_POSTS', params: { category: 'programming' } }
, , API
:
debounce
throttle
( ) redux-thunk, , . redux-saga, .
redux-thunk
. , , (. redux doc ).
Source: https://habr.com/ru/post/1663474/More articles:Значение параметра переопределения Javascript перед установкой - javascriptSwift 3 - How to define a callback function as a parameter - functionIs this the correct async wait diagram? - multithreadingScala Play 2.5 Form bindFromRequest: Can't find the HTTP request here? - scalaPerl: removing array elements and resizing an array - arraysES6 Fat Arrow and brackets `(...) => ({...})` - javascriptLemmainser uses NLTK - pythonJavascript Array.prototype.sort () is wrong without comparing a function - javascriptУчитывая линейный порядок, полностью представленный списком кортежей строк, выведите порядок в виде списка строк - pythonhow does "non x" work in a python set method? - pythonAll Articles