Depending on one variable I want to implement conditional rendering. Source code:
My variable
let hideDeleteButton = false;
useEffect - to check value of the variable
useEffect(() => { if (projects?.length === 0 || useCases?.length === 0) { hideDeleteButton = false; } else { hideDeleteButton = true; } }, []);
Conditional rendering
const DeleteButton = () => hideDeleteButton ? ( <Tooltip content={<TooltipContent title="The component belongs to either project or use case." />} > <span> <Button disabled onClick={handleDelete} color="error" classes={{ root: classes.button }}> {t('catalogPage.componentDetails.actionBar.deleteComponent')} </Button> </span> </Tooltip> ) : ( <Button onClick={handleDelete} color="error" classes={{ root: classes.button }}> {t('catalogPage.componentDetails.actionBar.deleteComponent')} </Button> ); return ( <ActionBar> <DeleteButton /> </ActionBar> );
And I got such kind of warning:
Assignments to the 'hideDeleteButton' variable from inside React Hook useEffect will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside useEffect
What sould I do exactly?