install and use redux to fetch data from server

This commit is contained in:
Bilal Catic
2019-05-28 04:39:50 +02:00
parent 0100f15960
commit 6cc3643501
9 changed files with 124 additions and 8 deletions

View File

@@ -0,0 +1,17 @@
import {
FETCH_DOOR_LOCK_CHARGES_PENDING,
FETCH_DOOR_LOCK_CHARGES_SUCCESS,
FETCH_DOOR_LOCK_CHARGES_FAILED
} from "../constants";
export const fetchDoorLockCharges = (dispatch) => {
dispatch({type: FETCH_DOOR_LOCK_CHARGES_PENDING});
fetch('/api/doorLockCharges')
.then(response => response.json())
.then(data => {
dispatch({type: FETCH_DOOR_LOCK_CHARGES_SUCCESS, payload: data})
})
.catch(err => {
dispatch({type: FETCH_DOOR_LOCK_CHARGES_FAILED, payload: err})
})
};