Skip to content

Commit

Permalink
Updaet readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mayank1513 committed Jun 13, 2024
1 parent cc8a11e commit 6128f30
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ I've developed fantastic libraries leveraging React18 features using Zustand, an

As a solution, I set out to create a lightweight, bare minimum store that facilitates shared state even when importing components from separate files, optimizing tree-shaking.

> If you need fully featured state management solution, consider using Zustand with [`treeshakable`](https://github.com/react18-tools/treeshakable/)
> To understand the issue with treeshakability and importing from subpath, see - <https://treeshakable.vercel.app>
## Features

✅ Full TypeScript Support
Expand All @@ -28,6 +31,12 @@ Utilize this hook similarly to the `useState` hook. However, ensure to pass a un
const [state, setState] = useRGS<number>("counter", 1);
```

**_or_**

```tsx
const [state, setState] = useRGS<number>("counter", () => 1);
```

> For detailed instructions, see [Getting Started](./md-docs/1.getting-started.md)
## Using Plugins
Expand Down
10 changes: 10 additions & 0 deletions md-docs/1.getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ You can access the same state across all client-side components using a unique k

> It's advisable to store your keys in a separate file to prevent typos and unnecessary conflicts.
### Initializing the state with a function

In some cases you might want to initialize the state with a function, for example, when reading from `localStorage`. We support initializer function as well.

```tsx
const [state, setState] = useRGS<number>("counter", () =>
typeof localStorage === "undefined" ? 1 : localStorage.getItem("counter") ?? 1,
);
```

### Example

```tsx
Expand Down

0 comments on commit 6128f30

Please sign in to comment.