diff --git a/README.md b/README.md index cb1a5cfc..385c3a04 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,7 @@ const CustomComponent = () => { - [x] List (ordered, unordered) - [x] Horizontal Rule - [x] Table +- [x] React Components (via `useMarkdownWithComponents`) - [ ] HTML Ref: [CommonMark](https://commonmark.org/help/) @@ -119,6 +120,77 @@ Ref: [CommonMark](https://commonmark.org/help/) > HTML will be treated as plain text. Please refer [issue#290](https://github.com/gmsgowtham/react-native-marked/issues/290) for a potential solution ## Advanced + +### Embedding React Components in Markdown + +You can embed React components directly in your markdown using JSX-style syntax. This is useful for adding interactive elements like buttons, custom info boxes, or any other React component. + +```tsx +import React, { Fragment } from "react"; +import { Pressable, ScrollView, Text, View } from "react-native"; +import { + ReactComponentRegistryProvider, + useMarkdownWithComponents, + type ReactComponentRegistry, +} from "react-native-marked"; + +// Define your components +const components: ReactComponentRegistry = { + Button: ({ props }) => ( + console.log("Pressed!")}> + {String(props.label ?? "Click me")} + + ), + InfoBox: ({ props, children }) => ( + + {props.title && {String(props.title)}} + {children} + + ), +}; + +const markdown = ` +# Hello World + +Click the button below: + +