Skip to content

Commit

Permalink
chore: Headerのprops初期化タイミングを調整
Browse files Browse the repository at this point in the history
  • Loading branch information
AtsushiM committed Jan 16, 2025
1 parent b7624b6 commit 55be29a
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/smarthr-ui/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ type Props = {

type ElementProps = Omit<ComponentProps<'header'>, keyof Props>

const COMMON_GAP = { column: 0.25, row: 0 }
const CHILDREN_GAP = { column: 0.5, row: 0.25 }
const COMMON_GAP = { column: 0.25, row: 0 } as const
const CHILDREN_GAP = { column: 0.5, row: 0.25 } as const

export const Header: React.FC<PropsWithChildren<Props> & ElementProps> = ({
enableNew,
logo,
logoHref = '/',
logoHref,
featureName,
apps = [],
apps,
tenants,
currentTenantId,
onTenantSelect,
Expand Down Expand Up @@ -120,15 +120,15 @@ export const Header: React.FC<PropsWithChildren<Props> & ElementProps> = ({
}

const Logo = React.memo<
Pick<Props, 'enableNew'> & { children: Props['logo']; href: Props['href']; className: string }
Pick<Props, 'enableNew'> & { children: Props['logo']; href: Props['logoHref']; className: string }
>(({ children, href, enableNew, className }) => (
<a href={href} className={className}>
<a href={href || '/'} className={className}>
{children || <SmartHRLogo fill={enableNew ? 'brand' : undefined} className="shr-p-0.75" />}
</a>
))

const MemoizedAppLauncher = React.memo<Pick<Props, 'featureName' | 'apps' | 'enableNew'>>(
({ featureName, apps, enableNew, featureName }) => {
({ featureName, apps, enableNew }) => {
const decorators = useMemo(() => {
if (!featureName) {
return undefined
Expand All @@ -137,7 +137,9 @@ const MemoizedAppLauncher = React.memo<Pick<Props, 'featureName' | 'apps' | 'ena
return { triggerLabel: () => featureName }
}, [featureName])

return featureName && <AppLauncher apps={apps} enableNew={enableNew} decorators={decorators} />
return (
featureName && <AppLauncher apps={apps || []} enableNew={enableNew} decorators={decorators} />
)
},
)

Expand Down Expand Up @@ -175,7 +177,7 @@ const TenantSwitcher = React.memo<
})

const MultiTenantDropdownMenuButton = React.memo<
Pick<Required<Props>, 'tenants'> & Pick<Props, 'onTenantSelect'> & { label: string }
Pick<Required<Props>, 'tenants'> & Pick<Props, 'onTenantSelect'> & { label: ReactNode }
>(({ label, tenants, onTenantSelect }) => {
const onClick = useMemo(
() =>
Expand Down

0 comments on commit 55be29a

Please sign in to comment.