0.1.1 • Published 6 years ago

choo-data v0.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

choo-data

Simple data fetching plugin for Choo with SSR (server-side rendering) support.

Requires choo-async.

Usage - Install - License: MIT

stability standard

Usage

const choo = require('choo')
const data = require('choo-data')
const async = require('choo-async')
const html = require('choo-async/html')

const app = async(choo())

app.use(data())
app.route('/', view)
app.mount('body')

async function view (state, emit) {
  const post = await app.data.load('post', getData, 1)
  return html`
    <body>
      ${post
        ? html`<p>${post.title}</p>`
        : html`<p>Loading...</p>`
      }
    </body>
  `
}

async function getData (id) {
  const response = await fetch(`https://jsonplaceholder.typicode.com/posts/${id}`)
  return response.json()
}

See examples for more

Install

npm install choo-data

License

MIT