validateDOMNesting(...): <a> cannot appear as a descendant of <a>.
See original GitHub issueI’m trying to make whole Media clickable, but got the warning: index.js:2178 Warning: validateDOMNesting(…): cannot appear as a descendant of .
import React from 'react';
import { Media } from 'reactstrap';
class someClass extends React.Component {
render() {
const item = this.props.item
const url = item.url
return (
<a className="someClass" href={url}>
<Media className="mt-1 align media-block">
<Media left bottom>
<img src={item.image} alt="logo" className="media-logo"/>
</Media>
<Media body>
<Media heading>
{item.name}
</Media>
{item.description}
</Media>
</Media>
</a>
)
}
}
export default someClass;
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Warning: validateDOMNesting(...): <a> cannot appear as a ...
Warning: validateDOMNesting(...): <a> cannot appear as a descendant of <a>. I don't know what to do. I needed to style the router navigation ......
Read more ><a> cannot appear as a descendant of < ...
So you are getting error,. Warning: validateDOMNesting(…): <a> cannot appear as a descendant of <a>. To solve this just use one of the...
Read more >Warning: validateDOMNesting(...): <button> cannot appear as ...
Warning: validateDOMNesting(...): <button> cannot appear as a descendant of <button>. in button ; Priority, Normal N ; Type, Bug ; State, Open O...
Read more >“Warning: validateDOMNesting(...): <a> cannot appear as a ...
“Warning: validateDOMNesting(...): <a> cannot appear as a descendant of <a> material ui” Code Answer's · validateDOMNesting(...): cannot appear as a descendant ...
Read more >button cannot appear as a descendant of button
Let's say we're given the following mock from a designer to list files in rows. Each row should be... Tagged with react, html....
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 Free
Top 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
Notice the
tag
prop on theMedia
which hasleft
, it’s needed for the workaround. The example I posted above has that and gets no errors or warnings.What @gergely-nagy said is correct, but I think this may also be a slight defect. reactstrap is defaulting
<Media left/right ...>
to an anchor tag (<a>
) which causing the nesteda
within ana
. We probably should only default that in the case there is anhref
prop (to indicate there should be a link)https://github.com/reactstrap/reactstrap/blob/6eac0fd5719eb07a2350bcd41462bc4a2946c8b8/src/Media.js#L40-L50
I think we can do some better defaulting there. For instance, not only can we only make it an anchor tag (
a
) when there is anhref
(attributes.href && (left || right)
, we probably should only make it an image tag (img
) when there is asrc
(attributes.src && object
)