shlogg · Early preview
Ramu Narasinga @karthik-m22

Understanding Zustand's UseBoundStoreWithEqualityFn Functionality

Zustand's useBoundStoreWithEqualityFn returns a function that updates the store with "api" using Object.assign. It's used in createWithEqualityFnImpl to return useBoundStoreWithEqualityFn.

In this article, we will understand how the useBoundStoreWithEqualityFn function is used in Zustand’s source code.

The above code is picked from https://github.com/pmndrs/zustand/blob/main/src/traditional.ts#L80
useBoundStoreWithEqualityFn is called in createWithEqualityFnImplfunction and returns another function named useStoreWithEqualityFn.
Let’s look at what’s in useStoreWithEqualityFn.

// Pulled from https://github.com/pmndrs/zustand/blob/main/src/traditional.ts#L80
export function useStoreWithEqualityFn<TState, StateSlice>(
  api: ReadonlyStoreApi<TState>,
  selector: (state: TState) =>...