Skip to content

Commit 36d42d6

Browse files
committed
fix for double wrap by immutable type #365 (comment)
1 parent d43572f commit 36d42d6

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

core/src/__tests__/Scoped.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,23 @@ test('object: should allow set to none via child without parent', async () => {
253253
expect(child.result.current.fieldUsedByChild.get()).toStrictEqual(undefined);
254254
expect(parentRenderTimes).toStrictEqual(1);
255255
expect(childRenderTimes).toStrictEqual(2);
256-
});
256+
});
257+
258+
test('object: should rerender used via scoped updates by child', async () => {
259+
let parentRenderTimes = 0
260+
let childRenderTimes = 0
261+
const parent = renderHook(() => {
262+
parentRenderTimes += 1;
263+
return useHookstate([1, 2, 3])
264+
});
265+
const child = renderHook(() => {
266+
childRenderTimes += 1;
267+
return useHookstate(parent.result.current)
268+
});
269+
270+
act(() => {
271+
// ensure no double wrap on type system
272+
// fix for https://github.com/avkonst/hookstate/discussions/365#discussioncomment-4478119
273+
child.result.current.set(p => { p[0] = 1; return p });
274+
});
275+
});

core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export const __state = Symbol('__state')
260260
* @ignore
261261
*/
262262
export interface __State<S, E> {
263-
[__state]: [Immutable<S>, E]
263+
[__state]: [S, E]
264264
}
265265

266266
/**

0 commit comments

Comments
 (0)