`closeToast` does not work
See original GitHub issueHere is a sample from the doc, you can also try it on codesandbox :
import React from "react";
import { ToastContainer, toast } from "react-toastify";
const Msg = ({ closeToast, toastProps }) => (
<div>
Lorem ipsum dolor {toastProps.position}
<button>Retry</button>
<button onClick={closeToast}>Close</button>
</div>
);
export default function App() {
const displayMsg = () => {
toast(<Msg />);
// toast(Msg) would also work
};
return (
<div>
<button onClick={displayMsg}>Click me</button>
<ToastContainer />
</div>
);
}
The toast should close when the close button is clicked, but it’s not. I tried in practice in my own code, it does not work either.
({ closeToast, toastProps }) => closeToast() // Broken
({ closeToast, toastProps }) => toastProps.closeToast() // Broken
({ closeToast, toastProps }) => toastProps.deleteToast() // Works, but there is no animation (it's expected I believe)
What’s required to make this work ?
Versions :
react-toastify 7.0.3
react 17.0.1
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Warning: React does not recognize the `closeToast` on using ...
Hello,. I'm using custom css classes in my web-app to style the default toastr message. The resultant toastr message looks like this:.
Read more >Toast is not rendered (react-toastify component) - Stack Overflow
ACTION.MOUNTED, function (containerInstance) { container = containerInstance; toaster.isActive = function (id) ...
Read more >React does not recognize the `closeToast` prop on a DOM ...
I am getting following console warning every time, I invoke toast. react_devtools_backend.js:2430 Warning: React does not recognize the closeToast prop on a DOM ......
Read more >Render more than string | React-Toastify - GitHub Pages
When you render a component, a closeToast prop and the toastProps are injected into your component. Copy. import React from 'react';.
Read more >react-toastify - Bountysource
The problem is multiple fold (but possibly related): ... React does not recognize the `closeToast` prop on a DOM element. $ 0.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I c/c’ed the css into my style sheet and I’m customizing it. Things gonna work out ! Thank you for your quick responses
Indeed, the lib listens to
onAnimatedEnd
event to remove the element from the queue. With the minimal stylesheet, the element is removed but after a delay.Regarding your customization, isn’t it something that can be done by overriding some existing classes?