Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "[v5]: refactor useMemoSelector""
Browse files Browse the repository at this point in the history
This reverts commit 3c47301.
dai-shi committed Jan 21, 2024
1 parent 3c47301 commit cb333a9
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/react.ts
Original file line number Diff line number Diff line change
@@ -25,15 +25,13 @@ const useMemoSelector = <TState, StateSlice>(
selector: (state: TState) => StateSlice,
) =>
useMemo(() => {
let lastSlice: StateSlice
let lastState: TState
let prev: readonly [TState, StateSlice] | undefined
return () => {
const state = getState()
if (!Object.is(lastState, state)) {
lastSlice = selector(state)
lastState = state
if (!prev || !Object.is(prev[0], state)) {
prev = [state, selector(state)]
}
return lastSlice
return prev[1]
}
}, [getState, selector])

2 changes: 1 addition & 1 deletion src/react/shallow.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// import { useDebugValue } from 'react'
// import { useRef } from 'react'
// That doesnt work in ESM, because React libs are CJS only.
// The following is a workaround until ESM is supported.
// eslint-disable-next-line import/extensions

0 comments on commit cb333a9

Please sign in to comment.