Skip to content
Advertisement

Connecting actions to store outside a component?

So let’s suppose I have a store, with a redux-thunk middleware in it. I created the store and exported it like this:

JavaScript

I can now access it anywhere in my app. But what if I want to dispatch an action from anywhere? I have them declared e.g. in myAction.js:

JavaScript

Now I can import them and connect to my store/component like this:

JavaScript

My question is – what if I do not have a component and still want to dispatch actions declared like the one above?

Advertisement

Answer

You can dispatch actions from the store directly

JavaScript

Redux is a library by itself.

It has nothing to do with React, they just work well together based on React single source of truth and Redux one global store as the state of our application.

You can use redux in every JavaScript application.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement