Skip to content

Commit 2b70205

Browse files
authored
fix(eslint): fix react-hooks/set-state-in-effect issues (#7614)
* fix(eslint): fix react-hooks/set-state-in-effect issues * fix(connection-form): set show password initial state based on initial password
1 parent 91579ae commit 2b70205

File tree

23 files changed

+149
-432
lines changed

23 files changed

+149
-432
lines changed

configs/eslint-config-compass/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const chaiFriendly = require('eslint-plugin-chai-friendly');
88
// TODO(COMPASS-9459): disabling a bunch of new rules to unblock automatic updates
99
const tempNewEslintRulesDisabled = {
1010
'react-hooks/refs': 'off',
11-
'react-hooks/set-state-in-effect': 'off',
1211
'react-hooks/preserve-manual-memoization': 'off',
1312
'react-hooks/static-components': 'off',
1413
'@typescript-eslint/no-unsafe-enum-comparison': 'off',

packages/compass-components/src/components/content-with-fallback.spec.tsx

Lines changed: 0 additions & 113 deletions
This file was deleted.

packages/compass-components/src/components/content-with-fallback.tsx

Lines changed: 0 additions & 181 deletions
This file was deleted.

packages/compass-components/src/components/document-list/document-edit-actions-footer.tsx

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import React, { useCallback, useEffect, useRef, useState } from 'react';
1+
import React, {
2+
useCallback,
3+
useEffect,
4+
useMemo,
5+
useRef,
6+
useState,
7+
} from 'react';
28
import type HadronDocument from 'hadron-document';
39
import { DocumentEvents, ElementEvents } from 'hadron-document';
410
import type { Element } from 'hadron-document';
@@ -108,18 +114,6 @@ function useHadronDocumentStatus(
108114
[]
109115
);
110116

111-
useEffect(() => {
112-
if (status !== 'Initial') {
113-
return;
114-
}
115-
116-
if (editing) {
117-
updateStatus('Editing');
118-
} else if (deleting) {
119-
updateStatus('Deleting');
120-
}
121-
}, [status, updateStatus, editing, deleting]);
122-
123117
useEffect(() => {
124118
const onUpdate = () => {
125119
updateStatus(
@@ -214,7 +208,20 @@ function useHadronDocumentStatus(
214208
}
215209
}, [status, updateStatus]);
216210

217-
return { status, updateStatus, error };
211+
const derivedStatus = useMemo(() => {
212+
if (status !== 'Initial') {
213+
return status;
214+
}
215+
if (editing) {
216+
return 'Editing';
217+
}
218+
if (deleting) {
219+
return 'Deleting';
220+
}
221+
return status;
222+
}, [status, editing, deleting]);
223+
224+
return { status: derivedStatus, updateStatus, error };
218225
}
219226

220227
const container = css({

0 commit comments

Comments
 (0)