Hi I am learning hooks concept by developing a small application. I am using redux slices. I am not following traditional way to create state like([state, setState]), instead I am creating states under one variable called intialState. I am trying to perform CRUD operation in application by hitting an external API. I am trying to delete the value from the list by button click.Under intialState variable am having a state called courses:[], where I used to store the data from the end point. When I am performing Delete operation I want to setState for this courses. I have tried to set the state but I ended up with error. Can any one help me out with how to set state in below method. Thanks in advance. Below is my code.
const initialState = {
isLoading: false,
error: false,
courses: [],
};
//------------------Delete Course
export function deleteCourse(index, id) {
console.log('I am coming');
axios.delete(`edu/course/${id}`).then(res => {
const newCourseList = [...initialState.courses];
console.log('NEW COURSE LIST', newCourseList);
newCourseList.splice(index, 1);
setinitialState({ courses: newCourseList }); // If I am doing like this I am getting an
error
});
}