R
R
rsoinvi2018-06-30 16:46:49
redux
rsoinvi, 2018-06-30 16:46:49

How to dispatch data from the API to the storage right away?

Hello everyone, I can’t understand how to correctly dispatch data from the API to the storage
There is an input and there is an API Task
Substitute the value of the input in the API (this is a weather application) and dispatch to the storage

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-06-30
@rsoinvi

You can use redux-thunk related
article
An abstract example of an asynchronous action with a request:

const fetchUsers = params => async dispatch => {
  try {
    const data = await Api.fetchUsers(params);
    dispatch(fetchUsersSuccess(data));
  } catch (e) {
    dispatch(fetchUsersFail(e));
  }
}

In case of success, the data is dispatched to the store, in case of an error, an error is dispatched for further processing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question