Redux possibibilty to dispatch an action on server side

Viewed 2380

I'm beginner with redux and create universal react redux application.

Is this any option to dispatch async action on server side like store.dispatch(actions.getOutput()) on server side.

getOutput is an asynchronous action which fetch some api on call and change the state on redux.

I Know to dispatch it on client side with redux-thunk middleware but not understanding the process on server side

let context = {},
    status = 200;

const allReducers = combineReducers({
    ...reducers
});

const store = createStore(
    allReducers,
    compose(
        applyMiddleware(thunkMiddleware, promise)
    )
);



    const preloadedStore = store.getState()
    store.dispatch(actions.getStories());
    const finalState = store.getState();


    const ctx = ReactDomServer.renderToString(
    <Provider store={store}>
        <StaticRouter context={context} location={req.url}>
            <App/>
        </StaticRouter>
    </Provider>
    ),
    reactHelmet = ReactHelmet.renderStatic();

    if(context.url){
        return res.redirect(302, context.url);
    }

    if(context.status === 404){
        status = 404;
    }

    let page = renderOutput(ctx, finalState, reactHelmet);
    res.status(status).send(page);
1 Answers
Related