Skip to content

Commit

Permalink
fix: usememo children documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Geron committed Oct 31, 2023
1 parent 2cb6e45 commit 0305353
Showing 1 changed file with 19 additions and 27 deletions.
46 changes: 19 additions & 27 deletions docs/rules/require-usememo-children.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <OtherComponent data={list} />
## Incorrect
```JavaScript
function Component() {

<View>
<>
<OtherComponent />
</>
</View>
}

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 <OtherComponent data={memoizedList} />

## Correct
```JavaScript
function Component() {

const children = useMemo(() => (<OtherComponent />), []);
<View>
{children}
</View>
}

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

Expand Down

0 comments on commit 0305353

Please sign in to comment.