From c11c8097a4896d85926ea8775ed3d0753552324a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Gra=CC=88=C3=9Fl?= Date: Thu, 28 Jul 2022 09:30:39 +0200 Subject: [PATCH] fix(RBACProvider): Use ref to hold loading value --- packages/components/src/RBACProvider/RBACProvider.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/components/src/RBACProvider/RBACProvider.tsx b/packages/components/src/RBACProvider/RBACProvider.tsx index 065d12619..c589f8067 100644 --- a/packages/components/src/RBACProvider/RBACProvider.tsx +++ b/packages/components/src/RBACProvider/RBACProvider.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import { Access } from '@redhat-cloud-services/rbac-client'; import { Bullseye, Spinner } from '@patternfly/react-core'; @@ -21,11 +21,11 @@ export interface RBACProviderProps { } export const RBACProvider: React.FunctionComponent = ({ appName, children }) => { + const loading = useRef(false); const [permissionState, setPermissionState] = useState(initialPermissions); - let loading = false; const fetchPermissions = async () => { - loading = true; + loading.current = true; const { isOrgAdmin, permissions: userPermissions } = await getRBAC(appName, true); setPermissionState((currentPerms: any) => ({ @@ -34,11 +34,11 @@ export const RBACProvider: React.FunctionComponent = ({ appNa isOrgAdmin, permissions: userPermissions, })); - loading = false; + loading.current = false; }; useEffect(() => { - if (!loading && permissionState.permissions.length == 0) { + if (!loading.current && permissionState.permissions.length == 0) { fetchPermissions(); } }, [appName]);