delete item from apiCall need reload page to deleted from client delete item from apiCall need reload page to deleted from client mongoose mongoose

delete item from apiCall need reload page to deleted from client


you have to implement deleteTodo inside your todoSlice in order to remove the deleted id from your local state,

...    export const todoSlice = createSlice({      name: 'todos',      initialState: {        todos: [],        pending: null,        error: null,      },      reducers: {        deleteTodo: (state, action) => {          return state.filter((todo)=>todo.id!==action.payload.id);        },      },    });  ...

and of course you have to pass the payload with the id of the todo you want to remove

export const deleteOneTodo = async (id, dispatch) => {  try {    await axios.delete(`http://10.0.2.2:5000/todos/${id}`);    dispatch(deleteTodo({id:id}));  } catch (err) {    console.log(err);  }};

if you still have doubts you can follow this tutorial: https://www.youtube.com/watch?v=fiesH6WU63I


i just call 'getTodos' inside 'deleteOneTodo'and delete 'deleteTodo' from reduceri hope its a good practice

export const deleteOneTodo = async (id, dispatch) => {  try {    await axios.delete(`http://10.0.2.2:5000/todos/${id}`);     // i add this line =>     getTodos(dispatch);  } catch (err) {    console.log(err);  }};