Archived
1
0
Fork
You've already forked jsx-to-html
0
Serialize JSX to HTML directly and nothing more
This repository has been archived on 2024年03月02日. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
  • TypeScript 100%
Find a file
2023年10月06日 09:44:17 +07:00
.vscode initial commit 2023年09月30日 11:27:48 +07:00
packages chore: remove jsxkey 2023年10月06日 09:44:17 +07:00
.editorconfig initial commit 2023年09月30日 11:27:48 +07:00
.gitignore initial commit 2023年09月30日 11:27:48 +07:00
.prettierignore initial commit 2023年09月30日 11:27:48 +07:00
.prettierrc initial commit 2023年09月30日 11:27:48 +07:00
package.json initial commit 2023年09月30日 11:27:48 +07:00
pnpm-lock.yaml initial commit 2023年09月30日 11:27:48 +07:00
pnpm-workspace.yaml initial commit 2023年09月30日 11:27:48 +07:00
README.md initial commit 2023年09月30日 11:27:48 +07:00

jsx-to-html

Serialize JSX to HTML directly and nothing more, with fully typed JSX allowing for a nice experience.

Usage

Configure tsconfig.json as follows:

{
	"compilerOptions": {
		"jsx": "react-jsx",
		"jsxImportSource": "@intrnl/jsx-to-html"
	}
}

You can then use it to render JSX!

import { type JSXNode, render } from '@intrnl/jsx-to-html';
const Card = (props: { children?: JSXNode; title?: string }) => {
	return (
		<div class="card">
			<div class="card__title">{props.title}</div>
			<div class="card__body">{props.children}</div>
		</div>
	);
};
const App = () => {
	return (
		<>
			<h1>Hello!</h1>
			<Card title="Card title">
				<p>We're inside a card!</p>
			</Card>
		</>
	);
};
const result = render(<App />);
// -> '<h1>Hello!</h1><div class="card"><div class="card__title"> ...'