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:
parent
b77f3129f2
commit
13df715bfd
@ -182,7 +182,7 @@ export const ProjectActionsTable = ({
|
||||
disableSortBy: true,
|
||||
},
|
||||
],
|
||||
[actions, incomingWebhooks, serviceAccounts],
|
||||
[incomingWebhooks, serviceAccounts],
|
||||
);
|
||||
|
||||
const [initialState] = useState({
|
||||
|
@ -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,
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user