Warning validateDOMNesting in case toast message contains <div>
See original GitHub issueGot warning in Chrome: validateDOMNesting(...): <div> cannot appear as a descendant of <p>.
with material-ui’s <Alert>
inside toast message (or any other div)
Possible solution: replace 'p'
with 'div'
https://github.com/timolins/react-hot-toast/blob/9045f1ca73f7ec5301dc5a7bbea4a19f106384c0/src/components/toast-bar.tsx#L39
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:8 (3 by maintainers)
Top Results From Across the Web
How to fix Warning: validateDOMNesting(...): <div> cannot ...
im passing users list as a props to UserItem Component to make iterate on user list and displaying them on table. the list...
Read more >Jest throws a warning - validateDOMNesting(...): <td> cannot ...
The above works but jest throws a warning because render seems to render the stuff inside a <div> -- in this case td...
Read more >validatedomnesting(...) a cannot appear as a descendant of a react ...
According to this document, a tag can only contain inline elements. That means putting a tag inside it should be improper, since the...
Read more ><div> cannot appear as a child of <table> - You.com - You.com
Apparently this code is not valid and I get this error message in the console: Warning: validateDOMNesting(...): <div> cannot appear as a child...
Read more >Create A Toast Notification Component With React - YouTube
As it turns out.. creating a decent toast component with React is actually a bit more advanced than it might seem at first...
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
@albannurkollari Not sure if I got that correctly, but I think by replacing @ambroseus was referring to using
div
by default instead ofp
. This shouldn’t have too many drawbacks other than being a bit less semantic. The error itself wasn’t thrown by react-hot-toast, but by React itself because it renders incorrect HTML (nesting adiv
inside ap
tag).That said I agree that it should be possible to render a custom component, without having to go headless. Not sure yet what’s the best API here since there are two components (ToastBar + Message) that need to be replaced. Maybe a
disableStyles
option would do the trick as well.I’ll open a new issue regarding the message customisation.