Skip to content

Commit 9e74810

Browse files
committed
docs: update docs of rule 'react-x/no-nested-component-definitions'
1 parent d2330c1 commit 9e74810

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

packages/plugins/eslint-plugin-react-x/src/rules/no-nested-component-definitions.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,18 @@ react-x/no-nested-component-definitions
2323

2424
## Description
2525

26-
Disallow nesting component definitions inside other components.
26+
Disallows defining React components inside other components.
2727

28-
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.
28+
Component definitions inside other components cause them to be recreated on every render, which can lead to performance issues and unexpected behavior.
29+
30+
When a component is defined inside another component:
31+
32+
- It gets recreated on every render of the parent component
33+
- It loses its internal state when the parent rerenders
34+
- It defeats props memoization and optimization techniques
35+
- It creates new function references on every render
36+
37+
Instead, define every component at the top level.
2938

3039
## Examples
3140

0 commit comments

Comments
 (0)