UNPKG

use-st8

Version:

Single-function alternative for React.useState hook

1 lines 756 B
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import { useState } from \"react\"\n\nfunction st8() {\n switch(arguments.length) {\n case 0: return this[0]\n case 1: return void this[1](arguments[0])\n default: throw new Error(\"Expected 0 or 1 arguments\")\n }\n}\n\nexport type St8<T> = {\n (): T\n (newValue: T | ((current: T) => T)): void\n}\n\nexport function useSt8<T>(initial: (() => T) | T): St8<T> {\n return st8.bind(useState(initial))\n}\n\nexport default useSt8"],"names":["useSt8","initial","arguments","length","this","Error","bind","useState"],"mappings":"0CAegBA,EAAUC,UAb1B,kBACWC,UAAUC,aACR,SAAUC,KAAK,QACf,cAAeA,KAAK,GAAGF,UAAU,kBACvB,IAAIG,MAAM,+BAUlBC,KAAKC,EAASN"}