no-nested-components
Rule category
Correctness.
What it does
Prevents nesting component definitions inside other components.
Why is this bad?
Nesting component definitions inside other components is a common mistake that can be extremely slow and cause issues and bugs, and the state of components defined during rendering will not be preserved by React. Instead, define every component at the top level.
Examples
Failing
import React from "react";
function function Gallery(): voidGallery() {
function function (local function) Profile(): voidProfile() {Never define a component inside another component! /* ... */
}
// ...
}Passing
function function Gallery(): voidGallery() {
// ...
}
Declare components at the top levelfunction function Profile(): voidProfile() {
/* ... */
}When a child component needs some data from a parent, pass it by props instead of nesting definitions.