Skip to content

Commit

Permalink
improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mayank1513 committed Apr 20, 2024
1 parent d22a242 commit e2e7ed4
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/r18gs/src/use-rgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import { useSyncExternalStore } from "react";

type Listener = () => void;
type SetterArgType<T> = T | ((prevState: T) => T);
type Subscriber = (l: Listener) => () => void;
export type SetStateAction<T> = (val: SetterArgType<T>) => void;
export type SetterArgType<T> = T | ((prevState: T) => T);
export type SetStateAction<T> = (value: SetterArgType<T>) => void;

/**
* This is a hack to reduce lib size + readability + not encouraging direct access to globalThis
Expand Down Expand Up @@ -52,12 +52,13 @@ function init<T>(key: string, value?: T) {
* ```tsx
* const [state, setState] = useRGS<number>("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<T>(
key: string,
value?: T,
serverValue?: T,
): [T, (val: SetterArgType<T>) => void] {
export default function useRGS<T>(key: string, value?: T, serverValue?: T): [T, SetStateAction<T>] {
if (!globalRGS[key]) init(key, value);

const rgs = globalRGS[key] as RGS;
Expand Down

0 comments on commit e2e7ed4

Please sign in to comment.