Skip to content

Commit f46264e

Browse files
committed
docs: add readme note on prop-passing inside Markdown
1 parent 87d8bd3 commit f46264e

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The most lightweight, customizable React markdown component.
2828
- [Getting the smallest possible bundle size](#getting-the-smallest-possible-bundle-size)
2929
- [Usage with Preact](#usage-with-preact)
3030
- [Gotchas](#gotchas)
31+
- [Passing props to stringified React components](#passing-props-to-stringified-react-components)
3132
- [Significant indentation inside arbitrary HTML](#significant-indentation-inside-arbitrary-html)
3233
- [Code blocks](#code-blocks)
3334
- [Using The Compiler Directly](#using-the-compiler-directly)
@@ -621,6 +622,52 @@ Everything will work just fine! Simply [Alias `react` to `preact/compat`](https:
621622
622623
## Gotchas
623624
625+
### Passing props to stringified React components
626+
627+
Using the [`options.overrides`](#optionsoverrides---rendering-arbitrary-react-components) functionality to render React components, props are passed into the component in stringifed form. It is up to you to parse the string to make use of the data.
628+
629+
```tsx
630+
const Table: React.FC<
631+
JSX.IntrinsicElements['table'] & {
632+
columns: string
633+
dataSource: string
634+
}
635+
> = ({ columns, dataSource, ...props }) => {
636+
const parsedColumns = JSON.parse(columns)
637+
const parsedData = JSON.parse(dataSource)
638+
639+
return (
640+
<div {...props}>
641+
<h1>Columns</h1>
642+
{parsedColumns.map(column => (
643+
<span key={column.key}>{column.title}</span>
644+
))}
645+
646+
<h2>Data</h2>
647+
{parsedData.map(datum => (
648+
<span key={datum.key}>{datum.Month}</span>
649+
))}
650+
</div>
651+
)
652+
}
653+
654+
/**
655+
* Example HTML in markdown:
656+
*
657+
* <Table
658+
* columns={[{ title: 'Month', dataIndex: 'Month', key: 'Month' }]}
659+
* dataSource={[
660+
* {
661+
* Month: '2024-09-01',
662+
* 'Forecasted Revenue': '$3,137,678.85',
663+
* 'Forecasted Expenses': '$2,036,660.28',
664+
* key: 0,
665+
* },
666+
* ]}
667+
* />
668+
*/
669+
```
670+
624671
### Significant indentation inside arbitrary HTML
625672
626673
People usually write HTML like this:

0 commit comments

Comments
 (0)