DEV Community

Cover image for How to access DVA Store in UMI application?
Charanjit Singh
Charanjit Singh

Posted on

How to access DVA Store in UMI application?

Hi most of the react developers would find dvaJS and umiJS, heaven for state management and application development. Dva is elm based state management tool that use react-redux for state management.

Q: How to access DVA Store in UMI application, outside the component or without connect?

Q: How to dispatch DVA Store in UMI application, outside the component or without connect?

Answer

Q: How to access DVA Store in UMI application, outside the component or without connect?

A: https://v2.umijs.org/guide/with-dva.html#how-to-access-store-or-dispatch

It says use:

window.g_app._store
Enter fullscreen mode Exit fullscreen mode

Q: How to dispatch DVA Store in UMI application, outside the component or without connect?

A: https://v2.umijs.org/guide/with-dva.html#how-to-access-store-or-dispatch

It says use:

window.g_app._store.dispatch('namespace/action')
Enter fullscreen mode Exit fullscreen mode

Bonus:

Q: How to get state of DVA Store in UMI application, outside the component or without connect?

A: https://v2.umijs.org/guide/with-dva.html#how-to-access-store-or-dispatch

It says use:

window.g_app._store.getState()
Enter fullscreen mode Exit fullscreen mode

Available Functions:

asyncReducers: {}
dispatch: ƒ ()
getState: ƒ f()
replaceReducer: ƒ (n)
runSaga: ƒ ()
subscribe: ƒ subscribe(listener)
Enter fullscreen mode Exit fullscreen mode

Recommended: Instead of directly using it, write a Util that exports these functions.

Refer to https://stackoverflow.com/questions/63073047/how-to-access-dva-store-in-umi-application/63073048#63073048 for discussion on StackOverflow

Top comments (0)