eslint-plugin-react-hooks 7.1.0-canary-66ae640b-20251204 → 7.1.0-canary-378973b3-20251205
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -32223,6 +32223,7 @@ const EnvironmentConfigSchema = v4.z.object({
|
|
|
32223
32223
|
validateHooksUsage: v4.z.boolean().default(true),
|
|
32224
32224
|
validateRefAccessDuringRender: v4.z.boolean().default(true),
|
|
32225
32225
|
validateNoSetStateInRender: v4.z.boolean().default(true),
|
|
32226
|
+
enableUseKeyedState: v4.z.boolean().default(false),
|
|
32226
32227
|
validateNoSetStateInEffects: v4.z.boolean().default(false),
|
|
32227
32228
|
validateNoDerivedComputationsInEffects: v4.z.boolean().default(false),
|
|
32228
32229
|
validateNoDerivedComputationsInEffects_exp: v4.z.boolean().default(false),
|
|
@@ -50098,16 +50099,35 @@ function validateNoSetStateInRenderImpl(fn, unconditionalSetStateFunctions) {
|
|
|
50098
50099
|
}));
|
|
50099
50100
|
}
|
|
50100
50101
|
else if (unconditionalBlocks.has(block.id)) {
|
|
50101
|
-
|
|
50102
|
-
|
|
50103
|
-
|
|
50104
|
-
|
|
50105
|
-
|
|
50106
|
-
|
|
50107
|
-
|
|
50108
|
-
|
|
50109
|
-
|
|
50110
|
-
|
|
50102
|
+
const enableUseKeyedState = fn.env.config.enableUseKeyedState;
|
|
50103
|
+
if (enableUseKeyedState) {
|
|
50104
|
+
errors.pushDiagnostic(CompilerDiagnostic.create({
|
|
50105
|
+
category: ErrorCategory.RenderSetState,
|
|
50106
|
+
reason: 'Cannot call setState during render',
|
|
50107
|
+
description: 'Calling setState during render may trigger an infinite loop.\n' +
|
|
50108
|
+
'* To reset state when other state/props change, use `const [state, setState] = useKeyedState(initialState, key)` to reset `state` when `key` changes.\n' +
|
|
50109
|
+
'* To derive data from other state/props, compute the derived data during render without using state',
|
|
50110
|
+
suggestions: null,
|
|
50111
|
+
}).withDetails({
|
|
50112
|
+
kind: 'error',
|
|
50113
|
+
loc: callee.loc,
|
|
50114
|
+
message: 'Found setState() in render',
|
|
50115
|
+
}));
|
|
50116
|
+
}
|
|
50117
|
+
else {
|
|
50118
|
+
errors.pushDiagnostic(CompilerDiagnostic.create({
|
|
50119
|
+
category: ErrorCategory.RenderSetState,
|
|
50120
|
+
reason: 'Cannot call setState during render',
|
|
50121
|
+
description: 'Calling setState during render may trigger an infinite loop.\n' +
|
|
50122
|
+
'* To reset state when other state/props change, store the previous value in state and update conditionally: https://react.dev/reference/react/useState#storing-information-from-previous-renders\n' +
|
|
50123
|
+
'* To derive data from other state/props, compute the derived data during render without using state',
|
|
50124
|
+
suggestions: null,
|
|
50125
|
+
}).withDetails({
|
|
50126
|
+
kind: 'error',
|
|
50127
|
+
loc: callee.loc,
|
|
50128
|
+
message: 'Found setState() in render',
|
|
50129
|
+
}));
|
|
50130
|
+
}
|
|
50111
50131
|
}
|
|
50112
50132
|
}
|
|
50113
50133
|
break;
|
|
@@ -32050,6 +32050,7 @@ const EnvironmentConfigSchema = v4.z.object({
|
|
|
32050
32050
|
validateHooksUsage: v4.z.boolean().default(true),
|
|
32051
32051
|
validateRefAccessDuringRender: v4.z.boolean().default(true),
|
|
32052
32052
|
validateNoSetStateInRender: v4.z.boolean().default(true),
|
|
32053
|
+
enableUseKeyedState: v4.z.boolean().default(false),
|
|
32053
32054
|
validateNoSetStateInEffects: v4.z.boolean().default(false),
|
|
32054
32055
|
validateNoDerivedComputationsInEffects: v4.z.boolean().default(false),
|
|
32055
32056
|
validateNoDerivedComputationsInEffects_exp: v4.z.boolean().default(false),
|
|
@@ -49925,16 +49926,35 @@ function validateNoSetStateInRenderImpl(fn, unconditionalSetStateFunctions) {
|
|
|
49925
49926
|
}));
|
|
49926
49927
|
}
|
|
49927
49928
|
else if (unconditionalBlocks.has(block.id)) {
|
|
49928
|
-
|
|
49929
|
-
|
|
49930
|
-
|
|
49931
|
-
|
|
49932
|
-
|
|
49933
|
-
|
|
49934
|
-
|
|
49935
|
-
|
|
49936
|
-
|
|
49937
|
-
|
|
49929
|
+
const enableUseKeyedState = fn.env.config.enableUseKeyedState;
|
|
49930
|
+
if (enableUseKeyedState) {
|
|
49931
|
+
errors.pushDiagnostic(CompilerDiagnostic.create({
|
|
49932
|
+
category: ErrorCategory.RenderSetState,
|
|
49933
|
+
reason: 'Cannot call setState during render',
|
|
49934
|
+
description: 'Calling setState during render may trigger an infinite loop.\n' +
|
|
49935
|
+
'* To reset state when other state/props change, use `const [state, setState] = useKeyedState(initialState, key)` to reset `state` when `key` changes.\n' +
|
|
49936
|
+
'* To derive data from other state/props, compute the derived data during render without using state',
|
|
49937
|
+
suggestions: null,
|
|
49938
|
+
}).withDetails({
|
|
49939
|
+
kind: 'error',
|
|
49940
|
+
loc: callee.loc,
|
|
49941
|
+
message: 'Found setState() in render',
|
|
49942
|
+
}));
|
|
49943
|
+
}
|
|
49944
|
+
else {
|
|
49945
|
+
errors.pushDiagnostic(CompilerDiagnostic.create({
|
|
49946
|
+
category: ErrorCategory.RenderSetState,
|
|
49947
|
+
reason: 'Cannot call setState during render',
|
|
49948
|
+
description: 'Calling setState during render may trigger an infinite loop.\n' +
|
|
49949
|
+
'* To reset state when other state/props change, store the previous value in state and update conditionally: https://react.dev/reference/react/useState#storing-information-from-previous-renders\n' +
|
|
49950
|
+
'* To derive data from other state/props, compute the derived data during render without using state',
|
|
49951
|
+
suggestions: null,
|
|
49952
|
+
}).withDetails({
|
|
49953
|
+
kind: 'error',
|
|
49954
|
+
loc: callee.loc,
|
|
49955
|
+
message: 'Found setState() in render',
|
|
49956
|
+
}));
|
|
49957
|
+
}
|
|
49938
49958
|
}
|
|
49939
49959
|
}
|
|
49940
49960
|
break;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-hooks",
|
|
3
3
|
"description": "ESLint rules for React Hooks",
|
|
4
|
-
"version": "7.1.0-canary-
|
|
4
|
+
"version": "7.1.0-canary-378973b3-20251205",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/facebook/react.git",
|