score:4

export const GET_TODOS = 'GET_TODOS'
export const GET_TODOS_SUCCESS = 'GET_TODOS_SUCCESS'
export const GET_TODOS_FAILURE = 'GET_TODOS_FAILURE'

export function getTodos() {
  return dispatch => {
     dispatch({
        type: GET_TODOS
     })

     fetch(url) // or whatever way you're making API call
        .then(res => {
           parseString(res, (err, result) => {
              if (err) {
                 throw err
              }

              dispatch({
                 type: GET_TODOS_SUCCESS,
                 payload: result
              })
           })
        })
        .catch(err => {
              dispatch({
                 type: GET_TODOS_FAILURE,
                 payload: err
              })
        })
  }
}

Related Query

More Query from same tag