From bed3cf3bf7d3ec194d270ed844b856c399b4ea3d Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Fri, 18 Oct 2024 15:23:00 +0200 Subject: [PATCH] memoize mutation --- .../plural-cloud/EditPluralOIDCClient.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/www/src/components/overview/clusters/plural-cloud/EditPluralOIDCClient.tsx b/www/src/components/overview/clusters/plural-cloud/EditPluralOIDCClient.tsx index 7d7bd7fe8..44296bd59 100644 --- a/www/src/components/overview/clusters/plural-cloud/EditPluralOIDCClient.tsx +++ b/www/src/components/overview/clusters/plural-cloud/EditPluralOIDCClient.tsx @@ -83,6 +83,11 @@ function EditPluralOIDCClient({ [redirectUris, setRedirectUris] ) + const m = useMemo( + () => (!provider ? useCreateProviderMutation : useUpdateProviderMutation), + [provider] + ) + const attributes: OidcAttributes = useMemo( () => ({ name, @@ -100,12 +105,10 @@ function EditPluralOIDCClient({ refetch() }, [onClose, refetch]) - const [mutation, { loading, error }] = !provider - ? useCreateProviderMutation({ variables: { attributes }, onCompleted }) - : useUpdateProviderMutation({ - variables: { id: provider.id, attributes }, - onCompleted, - }) + const [mutation, { loading, error }] = m({ + variables: { id: provider?.id, attributes }, + onCompleted, + }) return (