Skip to content

microssr/ts-jsx-str

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TypeScript JSX renderer

This project provides a very simple renderer for JSX, without React/Vue or any other big framework.

This is especially useful for Server-Side Rendering, in order to transform JSX templates to string.

📦 Installation

$ yarn add -D @microssr/ts-jsx-str @microssr/typings-ts-jsx-str

🚧 Usage

In your tsconfig.json add the following:

{
  "compilerOptions": {
    "jsx": "react",
    "jsxFactory": "JSX.createElement",
    "types": ["@microssr/typings-ts-jsx-str"]
  }
}

Then in your-file.tsx:

import JSX from '@microssr/ts-jsx-str'

const greetings = (<h1>Hello World</h1>)
console.log(greetings)
// <h1>Hello World</h1>

Or with a function-based template:

import JSX from '@microssr/ts-jsx-str'

const Greet = ({ name }) => (<p>Hello {name}</p>)
const greetings = (<Greet name="world" />)
console.log(greetings)
// <p>Hello world</p>

📝 License

This library is released under the terms of the MIT License.