mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Merge 51620ac79c into sapling-pr-archive-mofeiZ
This commit is contained in:
@@ -8344,6 +8344,23 @@ const testsTypescript = {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
code: normalizeIndent`
|
||||
function MyComponent(props) {
|
||||
useEffect(() => {
|
||||
console.log(props.foo);
|
||||
});
|
||||
}
|
||||
`,
|
||||
options: [{requireExplicitEffectDeps: true}],
|
||||
errors: [
|
||||
{
|
||||
message:
|
||||
'React Hook useEffect always requires dependencies. Please add a dependency array or an explicit `undefined`',
|
||||
suggestions: undefined,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
@@ -67,6 +67,9 @@ const rule = {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
requireExplicitEffectDeps: {
|
||||
type: 'boolean',
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
@@ -90,10 +93,13 @@ const rule = {
|
||||
? rawOptions.experimental_autoDependenciesHooks
|
||||
: [];
|
||||
|
||||
const requireExplicitEffectDeps: boolean = rawOptions && rawOptions.requireExplicitEffectDeps || false;
|
||||
|
||||
const options = {
|
||||
additionalHooks,
|
||||
experimental_autoDependenciesHooks,
|
||||
enableDangerousAutofixThisMayCauseInfiniteLoops,
|
||||
requireExplicitEffectDeps,
|
||||
};
|
||||
|
||||
function reportProblem(problem: Rule.ReportDescriptor) {
|
||||
@@ -1340,6 +1346,15 @@ const rule = {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!maybeNode && isEffect && options.requireExplicitEffectDeps) {
|
||||
reportProblem({
|
||||
node: reactiveHook,
|
||||
message:
|
||||
`React Hook ${reactiveHookName} always requires dependencies. ` +
|
||||
`Please add a dependency array or an explicit \`undefined\``
|
||||
});
|
||||
}
|
||||
|
||||
const isAutoDepsHook =
|
||||
options.experimental_autoDependenciesHooks.includes(reactiveHookName);
|
||||
|
||||
|
||||
+1
-1
@@ -908,7 +908,7 @@ export function scheduleUpdateOnFiber(
|
||||
markRootUpdated(root, lane);
|
||||
|
||||
if (
|
||||
(executionContext & RenderContext) !== NoLanes &&
|
||||
(executionContext & RenderContext) !== NoContext &&
|
||||
root === workInProgressRoot
|
||||
) {
|
||||
// This update was dispatched during the render phase. This is a mistake
|
||||
|
||||
Reference in New Issue
Block a user