Skip to content

Instantly share code, notes, and snippets.

@tudorilisoi
Created November 6, 2018 17:40
Show Gist options
  • Save tudorilisoi/5247ee0090f9648a7b98e6557ea72549 to your computer and use it in GitHub Desktop.
Save tudorilisoi/5247ee0090f9648a7b98e6557ea72549 to your computer and use it in GitHub Desktop.
//dashboard reducer
export default (allLists = [], action) => {
switch (action.type) {
case 'DASHBORD_FETCH_SUCCESS':
return action.data
case 'DASHBORD_FETCH_ERROR':
return []
default:
return allLists
}
}
export function fetchDashboard() {
return fetch(`${API_BASE_URL}/dashboard`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
//token here
}
})
.then(data => data.json())
.then(dataObj => {
dispatch({ type: 'DASHBORD_FETCH_SUCCESS', data: dataObj })
}).catch(err => {
dispatch({ type: 'DASHBORD_FETCH_ERROR' })
})
}
fetchDashboard()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment