Skip to content

How to use rehype-react single #52

Answered by ChristianMurphy
YutaUra asked this question in Q&A
Discussion options

You must be logged in to vote

I'd recommend using it as a unified plugin, as shown in the type tests https://github.com/rehypejs/rehype-react/blob/main/types/rehype-react-test.tsx
For your specific case where you only need to stringify/compile to HTML, it would look something like:

const reactElement = unified.use(rehypeReact, {
  createElement,
  components: {
    // custom component
    p: (props) => <SomeParagraph {...props} />,
  },
}).stringify(htmlAst).result

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@wooorm
Comment options

@YutaUra
Comment options

@YutaUra
Comment options

@ChristianMurphy
Comment options

Answer selected by YutaUra
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants