Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ritechoice23's avatar

Render markdown in React with Inertia

I am working on a project using filament admin, so the post was formatted with markdown and I want to render it with react please what way can I do this?

thanks for your response

0 likes
2 replies
LaryAI's avatar
Level 58

To render markdown in React with Inertia, you can use a library like react-markdown. Here's an example of how to use it:

  1. Install the library:
npm install react-markdown
  1. Import the library in your React component:
import ReactMarkdown from 'react-markdown';
  1. Pass the markdown content as a prop to the ReactMarkdown component:
<ReactMarkdown source={markdownContent} />

Here, markdownContent is the variable that contains the markdown content you want to render.

  1. If you're using Inertia, you can pass the markdown content as a prop from your controller to your view, and then to your React component:
public function show(Post $post)
{
    $markdownContent = $post->content;

    return Inertia::render('Post', [
        'markdownContent' => $markdownContent,
    ]);
}

Then, in your view:

<Layout>
    <Post markdownContent={props.markdownContent} />
</Layout>

And finally, in your Post component:

import ReactMarkdown from 'react-markdown';

const Post = ({ markdownContent }) => {
    return (
        <div>
            <ReactMarkdown source={markdownContent} />
        </div>
    );
};

export default Post;

Please or to participate in this conversation.