Phantom Stories Library - v0.0.8
    Preparing search index...

    Function ResourceRender

    • A component that renders a Resource ADT by matching its state to provided Data, Query, Empty, or Failure components. Supports merging common and state-specific props for flexible rendering.

      Type Parameters

      • T

        The type of the data in Data state.

      • Q

        The type of optional parameters.

      Parameters

      • props: Props<T, Q>

        The component props, including the Resource instance, rendering components, and optional props.

      Returns ReactNode

      A React node representing the rendered Resource state.

      const MyData: React.FC<DataProps<number, { id: string }>> = ({ value, params }) => <p>Data: {value}</p>;
      const MyQuery: React.FC<QueryProps<number, { id: string }>> = () => <p>Loading...</p>;
      const MyEmpty: React.FC<EmptyProps<number, { id: string }>> = () => <p>Empty</p>;
      const MyFailure: React.FC<FailureProps<number, { id: string }>> = ({ messages }) => <p>Errors: {messages.join(', ')}</p>;
      const resource = Resource.Data(42, { id: 'test' });
      <ResourceRender
      resource={resource}
      Data={MyData}
      Query={MyQuery}
      Empty={MyEmpty}
      Failure={MyFailure}
      commonProps={{ className: 'resource' }}
      matchingProps={{ Data: { style: { color: 'blue' } } }}
      />