R
R
rsoinvi2018-06-13 12:27:23
React
rsoinvi, 2018-06-13 12:27:23

How to get API data and put it in storage using redux-thunk?

Stuck on the redux-thunk stage
I want to put the data from the API into the store. Began to deal with redux-thunk. But something is still difficult.
Explain with a simple example what it is and what it is eaten with)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Aleksandrovich, 2018-06-13
@rsoinvi

export const endWorkingDay = () => (dispatch, getState) => {
      return axios.post(`${API_ROOT}/api/Account/EndWork?date=${endDate}&tradePointId=${id}&lat=${currentLat}&long=${currentLong}`,
          null,
          {
            headers: {
              Authorization: `Bearer ${token}`,
              "Content-Type": "application/json;charset=UTF-8",
            },
          }
        )
        .then(
response => {
          
          if (response.status === 200) {
            dispatch({
              type: SET_END_WORK_DATA,
              payload: {
                endWorkData: {
                  tradePointId: id,
                  lat: currentLat,
                  long: currentLong,
                  date: dateformat(new Date(), "yyyy-mm-dd"),
                  synced: true,
                },
              },
            })

We make a request and then use the dispatcher to transfer data to the store.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question