generated from react18-tools/turborepo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from react18-tools/refactor
Refactor
- Loading branch information
Showing
31 changed files
with
550 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,28 @@ | ||
import useRGS from "./use-rgs"; | ||
/* eslint-disable @typescript-eslint/non-nullable-type-assertion-style -- as ! operator is forbidden by eslint*/ | ||
import { createHook, createSetter, createSubcriber, globalRGS } from "./utils"; | ||
|
||
import type { SetStateAction } from "./utils"; | ||
|
||
export type { SetterArgType, SetStateAction, Plugin } from "./utils"; | ||
|
||
export default useRGS; | ||
/** | ||
* Use this hook similar to `useState` hook. | ||
* The difference is that you need to pass a | ||
* unique key - unique across the app to make | ||
* this state accessible to all client components. | ||
* | ||
* @example | ||
* ```tsx | ||
* const [state, setState] = useRGS<number>("counter", 1); | ||
* ``` | ||
* | ||
* @param key - Unique key to identify the store. | ||
* @param value - Initial 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): [T, SetStateAction<T>] { | ||
/** Initialize the named store when invoked for the first time. */ | ||
if (!globalRGS[key]) globalRGS[key] = [value, [], createSetter(key), createSubcriber(key)]; | ||
|
||
return createHook<T>(key); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./persist"; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.