Git Product home page Git Product logo

arrow-render-to-string's Introduction

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

arrow-render-to-string's People

Contributors

barelyhuman avatar prateek041 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

arrow-render-to-string's Issues

Stringification of dynamically generated array of partials

Doesn't stringify the output of the following

const tables = [1,2,3]

html`
    <div class="container">
      <div class="row">
        <div class="col">${() =>tables.map(x => html`<p>${x}</p>`)}</div>
      </div>
    </div>
  `

Workaround:

const tables = [1,2,3]
const tablesViews = state.tables.map(x => html`<p>${x}</p>`)

html`
    <div class="container">
      <div class="row">
        <div class="col">${tablesViews}</div>
      </div>
    </div>
  `

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.