TypeError: dispatch is not a function React and Redux TypeError: dispatch is not a function React and Redux

I get an error when I delete some lead(item). It deletes from the database but not from UI and gives this error dispatch is not a function.

//lead.js from /action
export const deleteLead = (id) => {
  return (dispatch) => {
    axios
      .delete(`/api/leads/${id}/`)
      .then((res) => {
        dispatch({
          type: DELETE_LEAD,
          payload: id,
        });
      })
      .catch((err) => console.log(err));
  };
};
//Frontend file 
import { getLeads, deleteLead } from "../../actions/leads";

<button
  onClick={deleteLead(lead.id)}
  className="btn btn-danger btn-sm">
   Delete
</button>


from Stackoverflow

Comments

Popular posts from this blog

With jQuery, how to automatically select the value of an input text that has been modified with the arrows? With jQuery, how to automatically select the value of an input text that has been modified with the arrows?

Cannot create an instance of a defined class in Javascript Cannot create an instance of a defined class in Javascript

Using Ts-Standard linting, JSDoc comment at beginning of file triggers "This rule requires the `strictNullChecks` compiler option" error Using Ts-Standard linting, JSDoc comment at beginning of file triggers "This rule requires the `strictNullChecks` compiler option" error