@delashum/vncache
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

vncache (very nice cache)

a library to manage state and caching for remote resources with a REST-like backend.

getting started

// cache.ts
import {resource, createResourceCache} from '@delashum/vncache'

type Task = {
  id: string
  name: string
  completed: boolean
}

const tasksResource = resource<Task>(async () => {
  const tasks = await fetchTasksFromBackend()
  return tasks
})

const $cache = createResourceCache({
  tasks: tasksResource,
})
// App.tsx
import {$cache} from './cache.ts'

const App = () => {
  const tasks = $cache.tasks.use()

  return (
    <div>
      {tasks.map(t => (
        <div>{t.name}</div>
      ))}
    </div>
  )
}

/@delashum/vncache/

    Package Sidebar

    Install

    npm i @delashum/vncache

    Weekly Downloads

    0

    Version

    1.0.4

    License

    ISC

    Unpacked Size

    61.5 kB

    Total Files

    14

    Last publish

    Collaborators

    • delashum