Skip to content
This repository has been archived by the owner on Sep 28, 2023. It is now read-only.

nearform/choo-data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Simple data fetching plugin for Choo with server-side rendering support

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published