From 701ad17ed3f523389e7d0bf9a006bef249645c3d Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Sat, 5 Apr 2025 17:40:58 +0200 Subject: [PATCH] Improve TSDoc comments for type `useStore` hook --- .changeset/red-scissors-visit.md | 5 +++++ packages/react/src/hooks/useStore.ts | 13 ++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 .changeset/red-scissors-visit.md diff --git a/.changeset/red-scissors-visit.md b/.changeset/red-scissors-visit.md new file mode 100644 index 00000000..28583d75 --- /dev/null +++ b/.changeset/red-scissors-visit.md @@ -0,0 +1,5 @@ +--- +'@xyflow/react': patch +--- + +Improve TSDoc comments for type `useStore` hook diff --git a/packages/react/src/hooks/useStore.ts b/packages/react/src/hooks/useStore.ts index 3b0a2778..f18fb9db 100644 --- a/packages/react/src/hooks/useStore.ts +++ b/packages/react/src/hooks/useStore.ts @@ -14,9 +14,13 @@ const zustandErrorMessage = errorMessages['error001'](); * state management library, so you should check out their docs for more details. * * @public - * @param selector - * @param equalityFn - * @returns The selected state slice + * @param selector - A selector function that returns a slice of the flow's internal state. + * Extracting or transforming just the state you need is a good practice to avoid unnecessary + * re-renders. + * @param equalityFn - A function to compare the previous and next value. This is incredibly useful + * for preventing unnecessary re-renders. Good sensible defaults are using `Object.is` or importing + * `zustand/shallow`, but you can be as granular as you like. + * @returns The selected state slice. * * @example * ```ts @@ -43,8 +47,7 @@ function useStore( /** * In some cases, you might need to access the store directly. This hook returns the store object which can be used on demand to access the state or dispatch actions. * - * @returns The store object - * + * @returns The store object. * @example * ```ts * const store = useStoreApi();