I am using json-server and build a fake JSON server to work with the react-redux app. I am working on delete method. Here is action
//Delete Employee
export const deleteEmployee = employeeId => dispatch => {
axios
.delete(`http://localhost:3004/employees?employeeId=${employeeId}`, {
headers: {
"Content-Type": "application/json"
}
})
.then(
dispatch({
type: DELETE_EMPLOYEE,
payload: employeeId
})
)
.catch(err => console.log(err));
};
Here is the db.json
[{
"name": "Joshua Fluke",
"title": "Designer",
"funFact": "This is my test app to test the delete functionality of the app",
"image": "http://placeholder.pics/svg/300x200/333333",
"employeeId": "12341234",
"dateOfJoining": "12/10/2016",
"id": 7
}]
Here is my delete reducer
case DELETE_EMPLOYEE:
return {
...state,
employees: state.employees.filter(
employee => employee.employeeId !== action.payload
),
loading: false
};
So delete is working fine visually as in when I click on the delete button it deletes the html but it does not delete the entry from db.json. How can I delete an entry in db.json of json-server.