From e2e7ed4cee09de1fb4232c25da6a58f4ea0d4696 Mon Sep 17 00:00:00 2001 From: Mayank Kumar Chaudhari Date: Sat, 20 Apr 2024 10:21:17 +0530 Subject: [PATCH] improve docs --- lib/r18gs/src/use-rgs.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/r18gs/src/use-rgs.ts b/lib/r18gs/src/use-rgs.ts index 82127b1a..123d5c30 100644 --- a/lib/r18gs/src/use-rgs.ts +++ b/lib/r18gs/src/use-rgs.ts @@ -2,9 +2,9 @@ import { useSyncExternalStore } from "react"; type Listener = () => void; -type SetterArgType = T | ((prevState: T) => T); type Subscriber = (l: Listener) => () => void; -export type SetStateAction = (val: SetterArgType) => void; +export type SetterArgType = T | ((prevState: T) => T); +export type SetStateAction = (value: SetterArgType) => void; /** * This is a hack to reduce lib size + readability + not encouraging direct access to globalThis @@ -52,12 +52,13 @@ function init(key: string, value?: T) { * ```tsx * const [state, setState] = useRGS("counter", 1); * ``` + * + * @param key - Unique key to identify the store. + * @param value - Initial value of the store. + * @param serverValue - Server value of the store. + * @returns - A tuple (Ordered sequance of values) containing the state and a function to set the state. */ -export default function useRGS( - key: string, - value?: T, - serverValue?: T, -): [T, (val: SetterArgType) => void] { +export default function useRGS(key: string, value?: T, serverValue?: T): [T, SetStateAction] { if (!globalRGS[key]) init(key, value); const rgs = globalRGS[key] as RGS;