Use with React
React site
import ReactDOM from 'react-dom'
import * as React from 'react'
import { tw } from 'twind'
ReactDOM.render(
<main className={tw`h-screen bg-purple-400 flex items-center justify-center`}>
<h1 className={tw`font-bold text(center 5xl white sm:gray-800 md:pink-700)`}>This is Twind!</h1>
</main>,
document.body,
)
htm/react - React with htm
import ReactDOM from 'react-dom'
import { html } from 'htm/react'
import { tw } from 'twind'
ReactDOM.render(
html`
<main className="${tw`h-screen bg-purple-400 flex items-center justify-center`}">
<h1 className="${tw`font-bold text(center 5xl white sm:gray-800 md:pink-700)`}">
This is Twind!
</h1>
</main>
`,
document.body,
)
🚀 live and interactive demo
Server Side Rendering
import { renderToString } from 'react-dom/server'
import { setup } from 'twind'
import { virtualSheet, getStyleTag } from 'twind/sheets'
import App from './app'
const sheet = virtualSheet()
setup({ ...sharedOptions, sheet })
function ssr() {
sheet.reset()
const body = renderToString(<App />)
const styleTag = getStyleTag(sheet)
return `<!DOCTYPE html>
<html lang="en">
<head>${styleTag}</head>
<body>${body}</body>
</html>
`
}