From 1eb457495793685c7270e050bd9aa4a72bec09a9 Mon Sep 17 00:00:00 2001 From: Tymoteusz Czech <2625371+Tymek@users.noreply.github.com> Date: Fri, 9 Aug 2024 16:21:56 +0200 Subject: [PATCH] refactor: remove ConditionallyRender component itself :tada: --- .../ConditionallyRender.tsx | 53 ------------------- 1 file changed, 53 deletions(-) delete mode 100644 frontend/src/component/common/ConditionallyRender/ConditionallyRender.tsx diff --git a/frontend/src/component/common/ConditionallyRender/ConditionallyRender.tsx b/frontend/src/component/common/ConditionallyRender/ConditionallyRender.tsx deleted file mode 100644 index dea335707db8..000000000000 --- a/frontend/src/component/common/ConditionallyRender/ConditionallyRender.tsx +++ /dev/null @@ -1,53 +0,0 @@ -import type { ReactNode } from 'react'; - -interface IConditionallyRenderProps { - condition: boolean; - show: TargetElement; - elseShow?: TargetElement; -} - -type TargetElement = - | JSX.Element - | JSX.Element[] - | RenderFunc - | ReactNode - | null; - -type RenderFunc = () => JSX.Element; - -export const ConditionallyRender = ({ - condition, - show, - elseShow, -}: IConditionallyRenderProps): JSX.Element | null => { - const handleFunction = (renderFunc: RenderFunc): JSX.Element | null => { - const result = renderFunc(); - if (!result) { - /* eslint-disable-next-line */ - console.warn( - 'Nothing was returned from your render function. Verify that you are returning a valid react component', - ); - return null; - } - return result; - }; - - const isFunc = (param: TargetElement): boolean => { - return typeof param === 'function'; - }; - - if (condition) { - if (isFunc(show)) { - return handleFunction(show as RenderFunc); - } - - return show as JSX.Element; - } - if (!condition && elseShow) { - if (isFunc(elseShow)) { - return handleFunction(elseShow as RenderFunc); - } - return elseShow as JSX.Element; - } - return null; -};