Skip to content

Commit

Permalink
docs: add readme note on prop-passing inside Markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
quantizor committed Nov 13, 2024
1 parent 87d8bd3 commit f46264e
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The most lightweight, customizable React markdown component.
- [Getting the smallest possible bundle size](#getting-the-smallest-possible-bundle-size)
- [Usage with Preact](#usage-with-preact)
- [Gotchas](#gotchas)
- [Passing props to stringified React components](#passing-props-to-stringified-react-components)
- [Significant indentation inside arbitrary HTML](#significant-indentation-inside-arbitrary-html)
- [Code blocks](#code-blocks)
- [Using The Compiler Directly](#using-the-compiler-directly)
Expand Down Expand Up @@ -621,6 +622,52 @@ Everything will work just fine! Simply [Alias `react` to `preact/compat`](https:
## Gotchas
### Passing props to stringified React components
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.
```tsx
const Table: React.FC<
JSX.IntrinsicElements['table'] & {
columns: string
dataSource: string
}
> = ({ columns, dataSource, ...props }) => {
const parsedColumns = JSON.parse(columns)
const parsedData = JSON.parse(dataSource)
return (
<div {...props}>
<h1>Columns</h1>
{parsedColumns.map(column => (
<span key={column.key}>{column.title}</span>
))}
<h2>Data</h2>
{parsedData.map(datum => (
<span key={datum.key}>{datum.Month}</span>
))}
</div>
)
}
/**
* Example HTML in markdown:
*
* <Table
* columns={[{ title: 'Month', dataIndex: 'Month', key: 'Month' }]}
* dataSource={[
* {
* Month: '2024-09-01',
* 'Forecasted Revenue': '$3,137,678.85',
* 'Forecasted Expenses': '$2,036,660.28',
* key: 0,
* },
* ]}
* />
*/
```
### Significant indentation inside arbitrary HTML
People usually write HTML like this:
Expand Down

0 comments on commit f46264e

Please sign in to comment.