1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-31 00:16:47 +01:00

fix: prevent infinite rerenders in useIncomingWebhooks (#6176)

React can sometimes be non-intuitive and behave erratically due to the
way it detects changes in hook dependencies.

This prevents infinite re-renders from `useIncomingWebhooks` by using a
static `DEFAULT_DATA` constant, so that its reference is always the
same, so no changes are detected when there are none.

Unrelated scouting, but this PR also removes an unneeded dependency in
the memoized columns in `ProjectActionsTable`.
This commit is contained in:
Nuno Góis 2024-02-09 08:17:15 +00:00 committed by GitHub
parent b77f3129f2
commit 13df715bfd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View File

@ -182,7 +182,7 @@ export const ProjectActionsTable = ({
disableSortBy: true,
},
],
[actions, incomingWebhooks, serviceAccounts],
[incomingWebhooks, serviceAccounts],
);
const [initialState] = useState({

View File

@ -8,13 +8,17 @@ import { useUiFlag } from 'hooks/useUiFlag';
const ENDPOINT = 'api/admin/incoming-webhooks';
const DEFAULT_DATA = {
incomingWebhooks: [],
};
export const useIncomingWebhooks = () => {
const { isEnterprise } = useUiConfig();
const incomingWebhooksEnabled = useUiFlag('incomingWebhooks');
const { data, error, mutate } = useConditionalSWR(
isEnterprise() && incomingWebhooksEnabled,
{ incomingWebhooks: [] },
DEFAULT_DATA,
formatApiPath(ENDPOINT),
fetcher,
);