Socket
Socket
Sign inDemoInstall

vanilla-swr

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    vanilla-swr

`stale-while-revalidate` caching strategy for vanilla web-apps


Version published
Maintainers
1
Created

Readme

Source

Vanilla SWR

stale-while-revalidate caching strategy for vanilla web-apps

GitHub Workflow Status Coverage Status

Installation

npm

npm install vanilla-swr

OR

yarn

yarn add vanilla-swr

OR

Import it from a CDN

jsDelivr
<script src="https://cdn.jsdelivr.net/npm/vanilla-swr/dist/index.min.js"></script>
unpkg
<script src="https://unpkg.com/vanilla-swr/dist/index.js"></script>

SWR variable is present in the window object.

Quick Start

import SWR from "vanilla-swr";

const fetcher = (...args) => fetch(...args).then((res) => res.json());

const observable = SWR("/api/data", fetcher);
// Use window.SWR("/api/data", fetcher) instead when using from the script tag

// Add a watcher to start fetching data
const watcher = observable.watch(({ data, error }) => {
  // data - data for given key resolved by fetcher
  // error - error thrown by fetcher
});

// Remove watcher when not needed
watcher.unwatch();

Documentation

https://vanilla-swr.js.org/

License

MIT

Keywords

FAQs

Last updated on 03 Apr 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc