davy_yg's avatar
Level 27

dispatch

What is dispatch for in Javascript?

for example:

 if(!tokenFromStorage){
          reject();  
        }
        dispatch(authSetToken(tokenfromStorage));
        resolve(tokenFromStorage);
0 likes
4 replies
bobbybouwmann's avatar

Well it depends on the frontend framework you use, but in general it's for dispatching a certain event. So you can say "I have an event that's going to be fired" and somewhere you in your app you can catch this event and perform some action. That's what we call listeners.

In other ways with React for example it can be the redux-thunk library (a popular middleware for Redux). Basically dispatch is used as a callback which gets invoked once some async action is complete. In redux-thunk dispatch is simply a function which dispatches an action to the Redux store.

It can also be an own defined method that does something, IDK!

So it can be anything! We need more information to be specific here!

artcore's avatar

Goedemorgen Bobby! I guess you didn't have to look it up first ;)

Please or to participate in this conversation.