From 9fd227d243b7e2a3780fc7b75b32064b1530d6fa Mon Sep 17 00:00:00 2001 From: daishi Date: Fri, 19 Jan 2024 21:00:52 +0900 Subject: [PATCH] fix(utils): atomWithReducer for jotai-scope --- src/vanilla/utils/atomWithReducer.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/vanilla/utils/atomWithReducer.ts b/src/vanilla/utils/atomWithReducer.ts index b9dd79d103..5799fb2f2a 100644 --- a/src/vanilla/utils/atomWithReducer.ts +++ b/src/vanilla/utils/atomWithReducer.ts @@ -15,8 +15,7 @@ export function atomWithReducer( initialValue: Value, reducer: (value: Value, action: Action) => Value, ) { - const anAtom: any = atom(initialValue, (get, set, action: Action) => - set(anAtom, reducer(get(anAtom), action)), - ) - return anAtom + return atom(initialValue, function (this: any, get, set, action: Action) { + set(this, reducer(get(this), action)) + }) }