Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add type assertion to React.JSX.Element type #867

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/packages/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ async function CodeBlock(props: Props) {
You can also call `codeToHast` to get the HTML abstract syntax tree, and render it using [`hast-util-to-jsx-runtime`](https://github.com/syntax-tree/hast-util-to-jsx-runtime). With this method, you can render your own `pre` and `code` components.

```tsx
import type { JSX } from 'react'
import type { BundledLanguage } from 'shiki'
import { toJsxRuntime } from 'hast-util-to-jsx-runtime'
import { Fragment } from 'react'
Expand Down Expand Up @@ -87,7 +88,7 @@ async function CodeBlock(props: Props) {
// your custom `pre` element
pre: props => <pre data-custom-codeblock {...props} />
},
})
}) as JSX.Element
}
```

Expand All @@ -99,6 +100,7 @@ We can start by creating a client `CodeBlock` component.
Create a `shared.ts` for highlighter:

```ts
import type { JSX } from 'react'
import type { BundledLanguage } from 'shiki/bundle/web'
import { toJsxRuntime } from 'hast-util-to-jsx-runtime'
import { Fragment } from 'react'
Expand All @@ -115,7 +117,7 @@ export async function highlight(code: string, lang: BundledLanguage) {
Fragment,
jsx,
jsxs,
})
}) as JSX.Element
}
```

Expand Down
Loading