mirror of
https://github.com/pmndrs/zustand.git
synced 2025-12-08 19:45:52 +00:00
fix: should use Object.is to compare two value (#1314)
This commit is contained in:
parent
43ea18e768
commit
ae4cc7f1b1
@ -72,7 +72,7 @@ const createStoreImpl: CreateStoreImpl = (createState) => {
|
||||
typeof partial === 'function'
|
||||
? (partial as (state: TState) => TState)(state)
|
||||
: partial
|
||||
if (nextState !== state) {
|
||||
if (!Object.is(nextState, state)) {
|
||||
const previousState = state
|
||||
state =
|
||||
replace ?? typeof nextState !== 'object'
|
||||
|
||||
@ -437,6 +437,17 @@ it('can set the store', () => {
|
||||
expect(getState().value).toBe(5)
|
||||
})
|
||||
|
||||
it('both NaN should not update', () => {
|
||||
const { setState, subscribe } = create<number>(() => NaN)
|
||||
|
||||
const fn = jest.fn()
|
||||
subscribe(fn)
|
||||
|
||||
setState(NaN)
|
||||
|
||||
expect(fn).not.toBeCalled()
|
||||
})
|
||||
|
||||
it('can set the store without merging', () => {
|
||||
const { setState, getState } = create<{ a: number } | { b: number }>(
|
||||
(_set) => ({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user