From 03053537a85ebf11c308adfb4027bdccbf01bf44 Mon Sep 17 00:00:00 2001 From: Arthur Geron Date: Tue, 31 Oct 2023 00:21:46 -0300 Subject: [PATCH] fix: usememo children documentation --- docs/rules/require-usememo-children.md | 46 +++++++++++--------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/docs/rules/require-usememo-children.md b/docs/rules/require-usememo-children.md index a944671..65a1794 100644 --- a/docs/rules/require-usememo-children.md +++ b/docs/rules/require-usememo-children.md @@ -20,40 +20,32 @@ This rule applies to any type of component (functional or class-based) as long a ## Rule Details This rule will enforce that all complex children are wrapped in `useMemo()`. -## Incorrect Code Examples - -Here are examples of incorrect code: - -```js -// Not using useMemo for complex children -function ComponentA(props) { - const list = getComplexData(); // Assume this returns an array - return +## Incorrect +```JavaScript +function Component() { + + + <> + + + } - -export default ComponentA; ``` - -## Correct Code Examples - -Here is an example of correct code pattern: - -```js -// Using useMemo for complex children -function ComponentB(props) { - const list = getComplexData(); // Assume this returns an array - - const memoizedList = React.useMemo(() => list, [list]); - - return + +## Correct +```JavaScript +function Component() { + + const children = useMemo(() => (), []); + + {children} + } - -export default ComponentB; ``` ## Options -No options available for this rule. +- `{strict: true}`: Fails even in cases where it is difficult to determine if the value in question is a primitive (string or number) or a complex value (object, array, etc.). ## When Not To Use It