Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

want to do dispatch.then(...)

I use redux, react-redux, react-router, and react-router-redux, and redux-thunk.

import { createStore, applyMiddleware } from 'redux'
import { Provider } from 'react-redux'
import { browserHistory } from 'react-router'
import { routerMiddleware } from 'react-router-redux'
import  thunkMiddleware from 'redux-thunk'
...    
const reduxRouterMiddleware = routerMiddleware( browserHistory )

const store = createStore(
    mainReducer,
    applyMiddleware(reduxRouterMiddleware, thunkMiddleware)
)

I was hoping as a result to be able to do thenable dispatch

dispatch(...).then()

but I get the message that then is not a function of dispatch.

How can I accomplish this?

like image 557
HenrikBechmann Avatar asked Mar 23 '16 21:03

HenrikBechmann


People also ask

Can we dispatch action from Saga?

Since you're using takeEvery , no, there's no way to dispatch a GET_USER action from within your saga without triggering an infinite loop.

How do you dispatch actions in Saga?

Create a plain JavaScript Object to instruct the middleware that we need to dispatch some action, and let the middleware perform the real dispatch. This way we can test the Generator's dispatch in the same way: by inspecting the yielded Effect and making sure it contains the correct instructions.

How do I dispatch action in reducer?

Dispatching an action within a reducer is an anti-pattern. Your reducer should be without side effects, simply digesting the action payload and returning a new state object. Adding listeners and dispatching actions within the reducer can lead to chained actions and other side effects.


1 Answers

the answer: it depends on what is returned by dispatch; if a promise is returned, then it will be thenable.

like image 70
HenrikBechmann Avatar answered Oct 03 '22 08:10

HenrikBechmann