Skip to content

Instantly share code, notes, and snippets.

View RaoHai's full-sized avatar
🎯
Focusing

陆沉 RaoHai

🎯
Focusing
View GitHub Profile
@nandorojo
nandorojo / no-cache-swr.js
Created October 21, 2020 17:20
No-cache policy with Vercel's SWR
import useNativeSWR from 'swr'
import { useRef } from 'react'
// inspired by https://github.com/vercel/swr/discussions/456
export default function useSWR(key, fetcher, options = {}) {
const { cachePolicy, ...opts } = options
const random = useRef(new Date())
return useNativeSWR(
() => {
@matianfu
matianfu / concurrent.js
Last active July 24, 2017 10:04
A base class for writing concurrent processes, with abort, until, race and settle.
// licensed under public domain
// author: [email protected]
const EventEmitter = require('events')
// K combinator, not necessary, just for fun
const K = x => y => x
// this class is mainly for settle logic.
// the concrete class should emit a 'finish' event with err/data at the end of the process