react-toastify icon indicating copy to clipboard operation
react-toastify copied to clipboard

toast not working with onClick in React

Open ag2byte opened this issue 5 years ago • 3 comments

** BUG REPORT **

toast not showing up using onClick event

I have a button component with the following definition:

<Button color="info" onClick={() => addToCart(item)}>
          Buy Now
        </Button>

addtocart function:

const addToCart = (item) => {
   
    console.log(item, "added");
   
    toast("🛒 success", {
      position: "top-left",
      autoClose: 5000,
      hideProgressBar: false,
      closeOnClick: true,
      pauseOnHover: true,
      draggable: true,
      progress: undefined,
    });
  };

The function is being called properly as the console.log(item,"added") line is working fine. Expected behavior: toast must be displayed but is not being rendered

ag2byte avatar Mar 10 '21 19:03 ag2byte

** BUG REPORT **

toast not showing up using onClick event

I have a button component with the following definition:

<Button color="info" onClick={() => addToCart(item)}>
          Buy Now
        </Button>

addtocart function:

const addToCart = (item) => {
   
    console.log(item, "added");
   
    toast("🛒 success", {
      position: "top-left",
      autoClose: 5000,
      hideProgressBar: false,
      closeOnClick: true,
      pauseOnHover: true,
      draggable: true,
      progress: undefined,
    });
  };

The function is being called properly as the console.log(item,"added") line is working fine. Expected behavior: toast must be displayed but is not being rendered

The same issue, have got the solution?

mppvgithub avatar Jul 27 '21 12:07 mppvgithub

** BUG REPORT ** toast not showing up using onClick event I have a button component with the following definition:

<Button color="info" onClick={() => addToCart(item)}>
          Buy Now
        </Button>

addtocart function:

const addToCart = (item) => {
   
    console.log(item, "added");
   
    toast("🛒 success", {
      position: "top-left",
      autoClose: 5000,
      hideProgressBar: false,
      closeOnClick: true,
      pauseOnHover: true,
      draggable: true,
      progress: undefined,
    });
  };

The function is being called properly as the console.log(item,"added") line is working fine. Expected behavior: toast must be displayed but is not being rendered

The same issue, have got the solution?

I basically used the toast type with the toast as

  toast.warning("❕ Item already exists", {
        position: "top-right",
        autoClose: 2000,
        hideProgressBar: false,
        closeOnClick: true,
        pauseOnHover: false,
        draggable: true,
        progress: undefined,
      });

ag2byte avatar Jul 27 '21 13:07 ag2byte

** BUG REPORT ** toast not showing up using onClick event I have a button component with the following definition:

<Button color="info" onClick={() => addToCart(item)}>
          Buy Now
        </Button>

addtocart function:

const addToCart = (item) => {
   
    console.log(item, "added");
   
    toast("🛒 success", {
      position: "top-left",
      autoClose: 5000,
      hideProgressBar: false,
      closeOnClick: true,
      pauseOnHover: true,
      draggable: true,
      progress: undefined,
    });
  };

The function is being called properly as the console.log(item,"added") line is working fine. Expected behavior: toast must be displayed but is not being rendered

The same issue, have got the solution?

I basically used the toast type with the toast as

  toast.warning("❕ Item already exists", {
        position: "top-right",
        autoClose: 2000,
        hideProgressBar: false,
        closeOnClick: true,
        pauseOnHover: false,
        draggable: true,
        progress: undefined,
      });

I used toast.configure(); this is works for me!

mppvgithub avatar Jul 27 '21 13:07 mppvgithub