New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@slimr/swr

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@slimr/swr

A tiny (~600B when bundled) hook that accepts a function callback, calls the function and returns a reactive callback state. Uses a cache and will return the cache value if available while waiting for the callback to complete, then update the return on co

latest
Source
npmnpm
Version
2.1.75
Version published
Weekly downloads
16
300%
Maintainers
1
Weekly downloads
 
Created
Source

🪶 @slimr/swr npm package

A tiny (~600B when bundled) hook that accepts a function callback, calls the function and returns a reactive callback state. Uses a cache and will return the cache value if available while waiting for the callback to complete, then update the return on complete. This is often called 'stale-while-refresh' and abbreviated as 'SWR', hence the name of the hook. Source is in @slimr/swr.

  • Only 440 bytes (minified + gzipped)
  • Shows cached data immediately and updates the UI when the callback resolves
  • Deduplicates concurrent requests: runs the callback only once if duplicates are requested
  • UX: no flickering, no waiting if cached, enables native scroll restoration

Context

@slimr is a set of slim React (hence '@slimr') libs. Check them all out on github!

Options

  • throttle - Throttle threshold in ms: time that the cache is deemed current, to avoid over re-fetching

Usage

import {useSWR} from `@slimr/swr`

function MyComponent({ page }: number) {
  const { result, loading, refresh} = useSWR(() => getPageData(page), [page], {throttle: Infinity})
  if (loading) return null
  return (
    <section>
      <h1>{result.title}</h1>
      <p>{result.description}</h1>
      <button onClick={refresh}>Refresh</button>
    </section>
  )
}

Keywords

preact

FAQs

Package last updated on 30 Dec 2025

Did you know?

Socket

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