choo-data

0.1.1 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i choo-data

Weekly Downloads

0

Version

0.1.1

License

MIT

Unpacked Size

6.7 kB

Total Files

10

Last publish

Collaborators

  • diffcunha