ilokesto

Show

Show는 when이 true로 resolve되면 children을, 아니면 fallback을 렌더링합니다.

import { Show } from '@ilokesto/utilinent';

<Show when={user} fallback={<LoginLink />}>
  {(currentUser) => <UserMenu user={currentUser} />}
</Show>

프로퍼티

PropType설명
whenT 또는 T[]조건 값입니다. Array는 모든 item이 truthy일 때만 true입니다.
childrenReactNode 또는 functionwhen이 true일 때 렌더링됩니다. Function children은 truthy value를 받습니다.
fallbackReactNodewhen이 false일 때 렌더링됩니다. 기본값은 null입니다.

Array condition

<Show when={[session, permissions.canEdit]} fallback={<ReadOnly />}>
  <Editor />
</Show>

Array condition은 every(Boolean)을 사용하므로 “모든 요구사항이 있어야 함”을 간결하게 표현할 수 있습니다.

Proxy tag

<Show.section when={open} className="panel" fallback={<Skeleton />}>
  <Settings />
</Show.section>

Show.section은 <section>을 만들고 DOM props/ref를 전달한 뒤 resolved branch를 element 안에 넣습니다.

주의 사항

  • 0, '', false, null, undefined는 falsy입니다.
  • Function children은 boolean이 아니라 원래 when value를 받습니다.
  • 복잡한 조건이 domain logic이라면 JSX 전에 계산하는 편이 좋습니다.

목차