Highlights on Redux

Written by zyydoosh, 20 Sep 2023

dispatch({"var": "test"})

What if we need to dispatch this action multiple times!?…. wrap in an action creator

function actionCreator() {return {"var": "test"}};

dispatch(actionCreator());

It’s funny that it’s called an action, but literally an object does nothing, want to execute logic?…. thunk function.

function thunk() {
	// logic, api calls, side effects, etc..
}

As a programmer you love wrapping, like we wrap an action inside an action creator, wrap thunk in a thunk action creator 😀

function thunk() {
	// logic, api calls, side effects, etc..
}

function thunkActionCreator () {return thunk();}

dispatch(thunkActionCreator());

What if we need to dispatch some action inside our function (thunk)?

What if the logic depends on the current redux root state?

What if we need to pass extra parameters?

function thunk(dispatch, getState, [ extraParams ]) {
	// logic, api calls, side effects, etc..
}

function thunkActionCreator () {return thunk();}

dispatch(thunkActionCreator());