Skip to content

Add block-level customization hooks - #208

Merged
haydenbleasel merged 2 commits into
vercel:mainfrom
FranciscoMoretti:block-level-flexibility
Nov 13, 2025
Merged

Add block-level customization hooks#208
haydenbleasel merged 2 commits into
vercel:mainfrom
FranciscoMoretti:block-level-flexibility

Conversation

@FranciscoMoretti

@FranciscoMoretti FranciscoMoretti commented Nov 7, 2025

Copy link
Copy Markdown
Contributor

Summary

  • export Block component and expose BlockComponent prop to override per-block rendering
  • allow callers to inject custom Markdown-to-blocks parser
  • document custom block component pattern reading from reactive stores
  • The parseMarkdownIntoBlocksFn is exported to allow user to re-use the calculation if they've already called externally (e.g. in a store)

Example usage

Using the streamdown Block with useMarkdownBlockByIndex, which is a hook from a user's application that only re-renders when this particular block changes (And obtains the block by its index).

const CustomBlock = memo(
  ({ messageId, partIdx, index, ...props }: BlockProps) => {
    const block = useMarkdownBlockByIndex(messageId, partIdx, index);
    if (block === null || block.trim() === "") {
      return null;
    }

    return <Block {...props}>{block}</Block>;
  },
  (prev, next) =>
    prev.messageId === next.messageId &&
    prev.partIdx === next.partIdx &&
    prev.index === next.index
);

@vercel

vercel Bot commented Nov 7, 2025

Copy link
Copy Markdown
Contributor

@FranciscoMoretti is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

@haydenbleasel

Copy link
Copy Markdown
Contributor

Nice work @FranciscoMoretti 🚀

@haydenbleasel
haydenbleasel merged commit f4c9c1e into vercel:main Nov 13, 2025
1 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants