A Payload site, ready to clone

Placeholder: rounded tiles in soft blue and orange

Writing a block, step by step

Two halves

A block is a Payload config, what editors fill in, plus a React server component, what visitors see. Each block has its own folder in a block package, with config.ts, Component.tsx, its CSS module and a styles.ts that lists its styles as plain data.

Keep the component free of Payload

Only config.ts imports from payload. The component takes plain props, all optional, and renders nothing for an empty one, so it works in any React host and old stored pages keep rendering. It takes the heading level and the style from the host, never picks a heading tag itself, and carries data-block and data-style on its root so themes can reach it.

Component.tsx
export function ExamplePromo({ heading, body, level = 2 }: ExamplePromoProps) {
  const Heading = `h${level}` as const
  return (
    <section data-block="examplePromo">
      {heading?.trim() && <Heading>{heading}</Heading>}
      {body?.trim() && <p>{body}</p>}
    </section>
  )
}

Never rename what is in use

Pages store blocks as JSON with their slug and field names, so renaming either orphans what is stored. To remove a block, move its slug to the package’s retired list. pnpm audit:blocks checks a package against the style guide.