R
R
rgs3502019-03-11 21:36:10
redux
rgs350, 2019-03-11 21:36:10

Redux Thunk. What for?

Hello. The question is in the title.
Why write like this (this is written in the documentation):

const INCREMENT_COUNTER = 'INCREMENT_COUNTER';

function increment() {
  return {
    type: INCREMENT_COUNTER
  };
}

function incrementAsync() {
  return dispatch => {
    setTimeout(() => {
      dispatch(increment());
    }, 1000);
  };
}

If you can write like this:
const INCREMENT_COUNTER = 'INCREMENT_COUNTER';

function increment() {
  return {
    type: INCREMENT_COUNTER
  };
}

function incrementAsync(dispatch) {
  setTimeout(() => {
    dispatch(increment());
  }, 1000);
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question