install and use redux to fetch data from server
This commit is contained in:
17
client/src/store/actions/doorLockActions.js
Normal file
17
client/src/store/actions/doorLockActions.js
Normal 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})
|
||||
})
|
||||
};
|
||||
Reference in New Issue
Block a user