You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
detailMessage='This state value shadows a value passed as a prop.';
191
-
break;
192
-
case'fromPropsOrState':
193
-
detailMessage=
194
-
'This state value shadows a value passed as a prop or a value from state.';
195
-
break;
196
-
}
197
191
198
192
/*
199
193
* If we use a setState from an invalid useEffect elsewhere then we probably have to
@@ -205,15 +199,29 @@ function generateCompilerError(
205
199
error.type!=='fromState'
206
200
){
207
201
compilerDiagnostic=CompilerDiagnostic.create({
208
-
description: `${error.description} This state value shadows a value passed as a prop. Instead of shadowing the prop with local state, hoist the state to the parent component and update it there.`,
209
-
category: `Local state shadows parent state.`,
202
+
description: `The setState within a useEffect is deriving from ${error.description}. Instead of shadowing the prop with local state, hoist the state to the parent component and update it there. If you are purposefully initializing state with a prop, and want to update it when a prop changes, do so conditionally in render`,
@@ -235,9 +243,11 @@ function generateCompilerError(
235
243
}
236
244
}else{
237
245
compilerDiagnostic=CompilerDiagnostic.create({
238
-
description: `${error.description} Derived values 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.`,
239
-
category: `Derive values in render, not effects.`,
246
+
description: `${error.description ? error.description.charAt(0).toUpperCase()+error.description.slice(1) : ''}. Derived values 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.`,
Copy file name to clipboardExpand all lines: compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useEffect/error.bug-derived-state-from-mixed-deps.expect.md
Error: You might not need an effect. Derive values in render, not effects.
38
38
39
-
This setState() appears to derive a value from both props and local state [prefix, name]. Derived values 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.
39
+
Both props and local state [prefix, name]. Derived values 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.
0 commit comments