Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dispatch an action to the redux-devtools store for importing a state from a component?

I'm currently trying to implement a panel integrated in my angular application which will allow me to import whatever json state file exported from redux-devtools using the same import feature as redux-devtools.

My application is properly integrated with @ngrx/store-devtools.

I can't figure out how to retrieve the devtools store from my component to then dispatch the action IMPORT_STATE as i saw on redux-devtools code:

store.liftedStore.dispatch({type: 'IMPORT_STATE', ...nextLiftedState});

The goal is to manually trigger the import state feature from redux-devtools but within a component of my application directly.

Is it possible to do that? And how to inject this store in my component to then use it?

Thanks in advance,

EDIT:

Actually, what i am trying to achieve is to have a component in my application which allows me to import different state (as json file) that i would have previously recorded from the redux-devtools extension to reach any pages of my application. Thus, this component needs to access to the redux-devtools store and dispatch the action IMPORT_STATE. What i did for the moment seems to not trigger the reducer for IMPORT_STATE action of the redux-devtools store. I think i'm missing something to include the redux-devtools store from the angular application.

Do you have any idea of how to achieve that?

Thanks in advance,

like image 248
Remi C Avatar asked Sep 03 '19 10:09

Remi C


People also ask

How do you dispatch in Redux dev tools?

Redux DevTool allows us to dispatch actions without writing any code. We can add our actions in dispatcher and it works just like action dispatched via Redux API. This kind of mocking helps in testing side effects and dependent actions. This feature becomes really handy when coupled with locking to the current state.

Which of the following functions can be used to dispatch actions in Redux?

You can dispatch an action by directly using store. dispatch(). However, it is more likely that you access it with react-Redux helper method called connect(). You can also use bindActionCreators() method to bind many action creators with dispatch function.

What is Dispatch in Redux?

dispatch is a function of the Redux store. You call store. dispatch to dispatch an action. This is the only way to trigger a state change. With React Redux, your components never access the store directly - connect does it for you.

How do I change state in Redux DevTools?

Step 1. Click Dispatcher. Step 2: Now provide which 'action type' you want to modify. Step 3: Create a payload object & modify the state which you want to modify.


1 Answers

To dispatch into the store from the dispatcher in the redux devtools you just enter in the action definition as json and then click dispatch.

for example:

{
type: 'IMPORT_STATE',
... whatever payload contents you need here ...
}

To open the dispatcher, click the little keyboard button in the middle at the bottom of the devtools.

enter image description here

like image 183
xandermonkey Avatar answered Sep 21 '22 08:09

xandermonkey