{ return { type: "CHANGE_TODO_COUNT", payload: newCount, }; }; export const Fe" /> { return { type: "CHANGE_TODO_COUNT", payload: newCount, }; }; export const Fe" /> { return { type: "CHANGE_TODO_COUNT", payload: newCount, }; }; export const Fe"/>

calling another function in another action

37 Views Asked by At
import Axios from "axios";

export const ChangeTodoCount = (newCount) => {
  return {
    type: "CHANGE_TODO_COUNT",
    payload: newCount,
  };
};

export const FetchToDo = () => {
  return (dispatch) => {
    Axios.get("http://localhost:2000/todo").then((response) => {
      dispatch({
        type: "GET_TODO",
        payload: response.data,
      });
      dispatch({
        type: "CHANGE_TODO_COUNT",
        payload: response.data.length,
      });
    });
  };
};

export const DeleteItem = (id) => {
  Axios.delete("http://localhost:2000/todo/" + id).then({ FetchToDo });
};

I'm trying to call FetchToDo after i run DeleteItem.

how would i need to add the FetchToDo to do that? Right now, when i clicked on the delete button, the list is deleted but i have to refresh the page to re-fetch the list.

1

There are 1 best solutions below

0
sandeep sharma On
`export const DeleteItem = (id) => {Axios.delete("http://localhost:2000/todo/" + id).then(()=>FetchToDo())};`