validateDOMNesting error in React

Just a guy who loves to write code and watch anime.
Search for a command to run...

Just a guy who loves to write code and watch anime.
No comments yet. Be the first to comment.
Qualities that make outstanding builders.

Bipedal vs quadrupedal: how many legs This is about the number of legs the creature walks on. Bipedal. Two legs. Humans, ostriches, T-rex, kangaroos, most fantasy humanoids. Quadrupedal. Four legs. Do

Intro You hear "lerp" and "smoothstep" everywhere in game dev. They sound like math jargon. They're not. Both are small tools that do the same job: smoothly move from one value to another. The problem

What is Kinematics Kinematics is the math field. It's the study of how things move without worrying about forces (which would be dynamics). FK and IK are the two branches: forward kinematics and inver

Intro Textures are usually the biggest cost in a 3D scene. Memory, bandwidth, and load time all get eaten by them. Resizing them is the obvious lever. There's more. This post is about the less obvious

The validateDOMNesting error in React occurs when the DOM elements are not properly nested according to the HTML specification.
The error message will look like this:
Warning: validateDOMNesting(...): <p> cannot appear as a descendant of <p>
This error tells us that the <p> element cannot be a descendant of another <p> element.
HTML has a defined set of rules for how elements can be nested.
Let's look at some examples of correct and incorrect nesting.
Elements must be properly nested and not overlap:
<p>This is <em>very <strong>wrong</em>!</strong></p> <!-- incorrect nesting -->
<p>This is <em>very <strong>correct</strong></em>.</p> <!-- correct nesting -->
Other examples would be nesting <a> elements inside <button> elements, or <button> elements inside <a> elements. Or them being nested inside each other, such as <a> inside <a>.
These examples are quite clear as to why they are incorrect, but why is nesting <p> elements inside <p> elements not allowed?
The <p> element cannot contain nested <p> elements or other block-level elements like <div>, <h1>, etc. This is because a paragraph (<p>) is meant to be a standalone block, representing a complete point.
The main issue is semantic meaning. The <p> element is meant to represent a single paragraph, a distinct part of a document discussing a specific idea. Nesting paragraphs within each other would complicate the structure, making it harder for both people and machines (like search engines or accessibility tools) to understand.