Skip to content

Render ArrowJS templates and partials to string. (Deno, Node, Bun, Browser)

License

Notifications You must be signed in to change notification settings

dumbjs/arrow-render-to-string

Repository files navigation

Frame 13

Render ArrowJS templates and partials to string.

Works wherever JS does.

Installation

npm install arrow-render-to-string

Usage/Examples

Basic

import { html } from '@arrow-js/core'
import { renderToString } from 'arrow-render-to-string'

const message = 'Hello World'
const view = html`<p>${message}</p>`

renderToString(view) //=> <p>Hello World</p>

Reactive Variables

import { html, reactive } from '@arrow-js/core'
import { renderToString } from 'arrow-render-to-string'

const state = reactive({
  count: 0,
})
const view = html`<p>${() => state.count}</p>`

renderToString(view) //=> <p>0</p>

Events

Events are stripped out, for you to re-hydrate on the client

import { html, reactive } from '@arrow-js/core'
import { renderToString } from 'arrow-render-to-string'

const state = reactive({
  count: 0,
})
const view = html`<button @click="${() => (state.count += 1)}">
  ${() => state.count}
</button>`

renderToString(view) //=> <button @click="<!--➳❍-->">0</button>

License

MIT