Skip to content

Commit b64f22e

Browse files
committed
Working but unoptimized
1 parent 66ddc6c commit b64f22e

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

lib/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const useRGS = <T>(
3434
u: createSubcriber(key, fields),
3535
};
3636

37-
return createHook<T>(key);
37+
return createHook<T>(key, fields);
3838
};
3939

4040
export { useRGS };

lib/src/utils.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ export const createSetter = <T>(key: string): SetStateAction<unknown> => {
6060
};
6161

6262
/** Extract coomon create hook logic to utils */
63-
export const createHook = <T>(key: string): [T, SetStateAction<T>] => {
63+
export const createHook = <T>(key: string, fields: (keyof T)[]): [T, SetStateAction<T>] => {
6464
const rgs = globalRGS[key] as RGS;
6565
/** This function is called by react to get the current stored value. */
6666
const getSnapshot = () => rgs.v as T;
67-
const val = useSyncExternalStore<T>(rgs.u as Subscriber, getSnapshot, getSnapshot);
67+
const u = createSubcriber(key, fields);
68+
const val = useSyncExternalStore<T>(u, getSnapshot, getSnapshot);
6869
return [val, rgs.s as SetStateAction<T>];
6970
};
7071

@@ -148,7 +149,8 @@ export const useRGSWithPlugins = <T>(
148149
value?: ValueType<T>,
149150
plugins?: Plugin<T>[],
150151
doNotInit = false,
152+
...fields: (keyof T)[]
151153
): [T, SetStateAction<T>] => {
152154
if (!globalRGS[key]?.s) initWithPlugins(key, value, plugins, doNotInit);
153-
return createHook<T>(key);
155+
return createHook<T>(key, fields);
154156
};

packages/shared/src/client/demo/with-selectors/with-selectors.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { UserData } from "./user-data";
77
export function WithSelector() {
88
return (
99
<div className={styles.preview}>
10-
{/* <Header /> */}
11-
{/* <Counter /> */}
10+
<Header />
11+
<Counter />
1212
<CounterWithoutSelectors />
1313
<UserData />
1414
</div>

0 commit comments

Comments
 (0)