Skip to content

Commit 93f6c7b

Browse files
committed
Update getting started
1 parent c0533e1 commit 93f6c7b

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

md-docs/1.getting-started.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ interface MyStore {
5252
};
5353
}
5454

55-
export const useStore = (...selectors: (keyof MyStore)[]) =>
55+
export const useStore = (includeRegExp?: RegExp | null | 0, excludeRegExp?: RegExp) =>
5656
useRGS<MyStore>(
5757
"my-store-with-selectors",
5858
{
@@ -63,14 +63,23 @@ export const useStore = (...selectors: (keyof MyStore)[]) =>
6363
age: 30,
6464
},
6565
},
66-
...selectors,
66+
includeRegExp,
67+
excludeRegExp,
6768
);
6869
```
6970

7071
And use it like
7172

7273
```ts
73-
const [{ count }, setState] = useStore("count");
74+
const [{ count }, setState] = useStore(/^count$/);
75+
```
76+
77+
or
78+
79+
```ts
80+
import { listToRegExp } from "r18gs/dist/utils";
81+
...
82+
const [{ count }, setState] = useStore(listToRegExp([count]));
7483
```
7584

7685
> Important: Please check out https://r18gs.vercel.app/ to learn how to use selectors.
@@ -81,7 +90,7 @@ In some cases you might want to initialize the state with a function, for exampl
8190

8291
```tsx
8392
const [state, setState] = useRGS<number>("counter", () =>
84-
typeof localStorage === "undefined" ? 1 : localStorage.getItem("counter") ?? 1,
93+
typeof localStorage === "undefined" ? 1 : (localStorage.getItem("counter") ?? 1),
8594
);
8695
```
8796

0 commit comments

Comments
 (0)