Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ Found 1 error:

Error: You might not need an effect. Derive values in render, not effects.

Derived values (From props: [value]) should be computed during render, rather than in effects. Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user.
Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user

This setState call is setting a derived value that depends on the following reactive sources:

Props: [value]

Data Flow Tree:
└── value (Prop)

See: https://react.dev/learn/you-might-not-need-an-effect#updating-state-based-on-props-or-state.

error.derived-state-conditionally-in-effect.ts:9:6
7 | useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@ Found 1 error:

Error: You might not need an effect. Derive values in render, not effects.

Derived values (From props: [input]) should be computed during render, rather than in effects. Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user.
Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user

This setState call is setting a derived value that depends on the following reactive sources:

Props: [input]

Data Flow Tree:
└── input (Prop)

See: https://react.dev/learn/you-might-not-need-an-effect#updating-state-based-on-props-or-state.

error.derived-state-from-default-props.ts:9:4
7 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@ Found 1 error:

Error: You might not need an effect. Derive values in render, not effects.

Derived values (From local state: [count]) should be computed during render, rather than in effects. Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user.
Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user

This setState call is setting a derived value that depends on the following reactive sources:

State: [count]

Data Flow Tree:
└── count (State)

See: https://react.dev/learn/you-might-not-need-an-effect#updating-state-based-on-props-or-state.

error.derived-state-from-local-state-in-effect.ts:10:6
8 | useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,18 @@ Found 1 error:

Error: You might not need an effect. Derive values in render, not effects.

Derived values (From props and local state: [firstName, lastName]) should be computed during render, rather than in effects. Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user.
Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user

This setState call is setting a derived value that depends on the following reactive sources:

Props: [firstName]
State: [lastName]

Data Flow Tree:
├── firstName (Prop)
└── lastName (State)

See: https://react.dev/learn/you-might-not-need-an-effect#updating-state-based-on-props-or-state.

error.derived-state-from-prop-local-state-and-component-scope.ts:11:4
9 |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

## Input

```javascript
// @validateNoDerivedComputationsInEffects_exp

function Component({value}) {
const [checked, setChecked] = useState('');

useEffect(() => {
setChecked(value === '' ? [] : value.split(','));
}, [value]);

return <div>{checked}</div>;
}

```


## Error

```
Found 1 error:

Error: You might not need an effect. Derive values in render, not effects.

Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user

This setState call is setting a derived value that depends on the following reactive sources:

Props: [value]

Data Flow Tree:
└── value (Prop)

See: https://react.dev/learn/you-might-not-need-an-effect#updating-state-based-on-props-or-state.

error.derived-state-from-prop-setter-ternary.ts:7:4
5 |
6 | useEffect(() => {
> 7 | setChecked(value === '' ? [] : value.split(','));
| ^^^^^^^^^^ This should be computed during render, not in an effect
8 | }, [value]);
9 |
10 | return <div>{checked}</div>;
```


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @validateNoDerivedComputationsInEffects_exp

function Component({value}) {
const [checked, setChecked] = useState('');

useEffect(() => {
setChecked(value === '' ? [] : value.split(','));
}, [value]);

return <div>{checked}</div>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@ Found 1 error:

Error: You might not need an effect. Derive values in render, not effects.

Derived values (From props: [value]) should be computed during render, rather than in effects. Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user.
Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user

This setState call is setting a derived value that depends on the following reactive sources:

Props: [value]

Data Flow Tree:
└── value (Prop)

See: https://react.dev/learn/you-might-not-need-an-effect#updating-state-based-on-props-or-state.

error.derived-state-from-prop-with-side-effect.ts:8:4
6 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ Found 1 error:

Error: You might not need an effect. Derive values in render, not effects.

Derived values (From props: [propValue]) should be computed during render, rather than in effects. Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user.
Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user

This setState call is setting a derived value that depends on the following reactive sources:

Props: [propValue]

Data Flow Tree:
└── propValue (Prop)

See: https://react.dev/learn/you-might-not-need-an-effect#updating-state-based-on-props-or-state.

error.effect-contains-local-function-call.ts:12:4
10 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,16 @@ Found 1 error:

Error: You might not need an effect. Derive values in render, not effects.

Derived values (From local state: [firstName]) should be computed during render, rather than in effects. Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user.
Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user

This setState call is setting a derived value that depends on the following reactive sources:

State: [firstName]

Data Flow Tree:
└── firstName (State)

See: https://react.dev/learn/you-might-not-need-an-effect#updating-state-based-on-props-or-state.

error.invalid-derived-computation-in-effect.ts:11:4
9 | const [fullName, setFullName] = useState('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@ Found 1 error:
Error: You might not need an effect. Derive values in render, not effects.
Derived values (From props: [props]) should be computed during render, rather than in effects. Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user.
Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user
This setState call is setting a derived value that depends on the following reactive sources:
Props: [props]
Data Flow Tree:
└── computed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yesss

└── props (Prop)
See: https://react.dev/learn/you-might-not-need-an-effect#updating-state-based-on-props-or-state.
error.invalid-derived-state-from-computed-props.ts:9:4
7 | useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,16 @@ Found 1 error:

Error: You might not need an effect. Derive values in render, not effects.

Derived values (From props: [props]) should be computed during render, rather than in effects. Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user.
Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user

This setState call is setting a derived value that depends on the following reactive sources:

Props: [props]

Data Flow Tree:
└── props (Prop)

See: https://react.dev/learn/you-might-not-need-an-effect#updating-state-based-on-props-or-state.

error.invalid-derived-state-from-destructured-props.ts:10:4
8 |
Expand Down
Loading