list.tsx 562 B

1234567891011121314151617
  1. "use client";
  2. import { type ComponentRenderProps } from "@json-render/react";
  3. import { useData } from "@json-render/react";
  4. import { getByPath } from "@json-render/core";
  5. export function List({ element, children }: ComponentRenderProps) {
  6. const { dataPath } = element.props as { dataPath: string };
  7. const { data } = useData();
  8. const listData = getByPath(data, dataPath) as Array<unknown> | undefined;
  9. if (!listData || !Array.isArray(listData)) {
  10. return <div style={{ color: "var(--muted)" }}>No items</div>;
  11. }
  12. return <div>{children}</div>;
  13. }