Skip to content

Commit 0dff902

Browse files
committed
docs: experimental builtin JSX support
1 parent fd38026 commit 0dff902

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,27 @@ Under the hood, it handles layout calculation, font, typography and more, to gen
5151
Satori only accepts JSX elements that are pure and stateless. You can use a subset of HTML
5252
elements (see section below), or custom React components, but React APIs such as `useState`, `useEffect`, `dangerouslySetInnerHTML` are not supported.
5353

54+
#### Experimental: builtin JSX support
55+
56+
Satori has an experimental JSX runtime that you can use without having to install React. You can enable it on a per-file basis with [`@jsxImportSource` pragmas](https://www.typescriptlang.org/tsconfig/#jsxImportSource). In the future, it will autocomplete only the subset of HTML elements and CSS properties that Satori supports for better type-safety.
57+
58+
```jsx
59+
/** @jsxRuntime automatic */
60+
/** @jsxImportSource satori/jsx */
61+
62+
import satori from 'satori';
63+
import { FC, JSXNode } from 'satori/jsx';
64+
65+
const MyComponent: FC<{ children: JSXNode }> = ({ children }) => (
66+
<div style={{ color: 'black' }}>{children}</div>,
67+
)
68+
69+
const svg = await satori(
70+
<MyComponent>hello, world</MyComponent>
71+
options,
72+
)
73+
```
74+
5475
#### Use without JSX
5576

5677
If you don't have JSX transpiler enabled, you can simply pass [React-elements-like objects](https://reactjs.org/docs/introducing-jsx.html) that have `type`, `props.children` and `props.style` (and other properties too) directly:
@@ -351,8 +372,6 @@ Multiple fonts can be passed to Satori and used in `fontFamily`.
351372
> [!TIP]
352373
> We recommend you define global fonts instead of creating a new object and pass it to satori for better performance, if your fonts do not change. [Read it for more detail](https://github.com/vercel/satori/issues/590)
353374
354-
355-
356375
#### Emojis
357376

358377
To render custom images for specific graphemes, you can use `graphemeImages` option to map the grapheme to an image source:

0 commit comments

Comments
 (0)