Skip to main content

Async component

Component này cho phép truyền vào status và hiển thị success, error, hoặc error UI

Ví dụ

import { AsyncComponent } from '@xobuilder/ui';

export const Demo = () => {
const { status, data } = getData();

return (
<AsyncComponent
status={status}
success={() => <div>{JSON.stringify(data)}</div>}

// Optional
isEmpty={data.length === 0}
loading={<AsyncComponent.Loading variant="skeleton-page" />}
error={<AsyncComponent.Error message="Error" />}
empty={<AsyncComponent.Empty message="Empty" />}
/>
)
}

AsyncComponent Props

NameTypeDefaultDescription
statusStatusidleTrạng thái của component
successReactNode-Component hiển thị khi status là success
loadingReactNode<AsyncComponent.Loading variant="spinner" />Component hiển thị khi status là loading
errorReactNode<AsyncComponent.Error />Component hiển thị khi status là error
emptyReactNode<AsyncComponent.Empty />Component hiển thị khi isEmpty là true
isEmptybooleanfalseTrạng thái empty của component

AsyncComponent.Empty Props

NameTypeDefaultDescription
messagestringNo dataMessage hiển thị

AsyncComponent.Error Props

NameTypeDefaultDescription
messageReactNodeErrorInlineErrorProps message
fieldIDstring-InlineErrorProps fieldID

AsyncComponent.Loading Props

NameTypeDefaultDescription
variantspinner | skeleton-page | skeleton-tabs | skeleton-body-text | skeleton-display-textspinnerLoại loading ứng với từng component loading của polaris