diff --git a/README.md b/README.md new file mode 100644 index 0000000..1b66241 --- /dev/null +++ b/README.md @@ -0,0 +1,159 @@ +# jrx + +JSX factory for [json-render](https://github.com/vercel-labs/json-render). Write JSX, get Spec JSON. + +## Install + +```bash +bun add jrx @json-render/core +``` + +## Setup + +Configure your `tsconfig.json` to use jrx as the JSX source: + +```json +{ + "compilerOptions": { + "jsx": "react-jsx", + "jsxImportSource": "jrx" + } +} +``` + +Or use a per-file pragma: + +```tsx +/** @jsxImportSource jrx */ +``` + +## Usage + +### Define components + +Create wrapper functions that map JSX tags to json-render component type names: + +```ts +import { jsx } from "jrx/jsx-runtime"; +import type { JrxNode } from "jrx"; + +export function Stack(props: Record): JrxNode { + return jsx("Stack", props); +} + +export function Text(props: Record): JrxNode { + return jsx("Text", props); +} + +export function Button(props: Record): JrxNode { + return jsx("Button", props); +} +``` + +### Render JSX to Spec JSON + +```tsx +import { render } from "jrx"; +import { Stack, Text, Button } from "./components"; + +const spec = render( + + +