question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Warning: React does not recognize the `closeToast` on using custom css classes

See original GitHub issue

Hello,

I’m using custom css classes in my web-app to style the default toastr message. The resultant toastr message looks like this:

toastr-screenshot

and I am using the following code to display a toastr and everything works well.

toast.success(We have successfully updated your preference., { className: "toasterSuccess", });

But, React throws me this warning whenever a toastr message is displayed on the screen:

Warning: React does not recognize the closeToast prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase closetoast instead. If you accidentally passed it from a parent component, remove it from the DOM element.

Can someone help me in suppressing these warnings?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
afozbekcommented, Feb 3, 2021

If anyone still doesnt understand the solution, all you have to do that create a React element as a wrapper for toastContent.

Old Code

// toast component
import { toast as alert } from "react-toastify";

const toast = (message, hasSuccess = true) => {
  // destructuring props

  // state

  // effect

  // other variables/functions
  let toastIcon = hasSuccess ? <i className="icon-success"></i> : <i className="icon-exclamation"></i>;
  let toastType = hasSuccess ? TOAST_TYPES.SUCCESS : TOAST_TYPES.ERROR;
  // render
  const toastContent = (
      <Col className="toast-content-wrapper">
        <div className="toast-icon">{toastIcon}</div>
        <div className="toast-message">{message}</div>
      </Col>
  );
  
  // toastType -> success | error -> toast.success | toast.error
  return (
    alert[toastType](toastContent)
  );
};

New Code

import { toast as alert } from "react-toastify";
// This container required for the first parameter of the toast function
const Container = (props) => <div>{props.children}</div>;

const toast = (message, hasSuccess = true) => {
  // destructuring props

  // state

  // effect

  // other variables/functions
  let toastIcon = hasSuccess ? <i className="icon-success"></i> : <i className="icon-exclamation"></i>;
  let toastType = hasSuccess ? TOAST_TYPES.SUCCESS : TOAST_TYPES.ERROR;
  // render
  const toastContent = (
    <Container>
      <Col className="toast-content-wrapper">
        <div className="toast-icon">{toastIcon}</div>
        <div className="toast-message">{message}</div>
      </Col>
    </Container>
  );
  return (
    alert[toastType](toastContent)
  );
};
4reactions
alish1129commented, Jul 2, 2020

What’s the answer to this error? I am getting it but I haven’t used any closeButton or closeToast prop.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React does not recognize the X prop on a DOM element ...
[Error] Warning: React does not recognize the isSignedIn prop on a DOM element. If you intentionally want it to appear in the DOM...
Read more >
react-toastify - npm
Start using react-toastify in your project by running `npm i ... using a custom close button, the component will receive a prop closeToast...
Read more >
Unknown Prop Warning - React
The unknown-prop warning will fire if you attempt to render a DOM element with a prop that is not recognized by React as...
Read more >
View Raw - UNPKG
BOTTOM_CENTER }); toast("Custom Style Notification with css class! ... import { ToastContainer } from 'react-toastify'; // close toast after 8 seconds const ...
Read more >
@repetere/react-toastify - npm package | Snyk
Easy to setup for real, you can make it work in less than 10sec! Super easy to customize; RTL support; Swipe to close;...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found