Search code examples
reduxumijsdvajs

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?


Solution

  • 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
    

    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')
    

    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()
    

    Available Functions:

    asyncReducers: {}
    dispatch: ƒ ()
    getState: ƒ f()
    replaceReducer: ƒ (n)
    runSaga: ƒ ()
    subscribe: ƒ subscribe(listener)
    

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