From dfbb3175b92949aed2b5a22701f486dc1d98310b Mon Sep 17 00:00:00 2001 From: wo-o29 Date: Sun, 31 Aug 2025 01:50:35 +0900 Subject: [PATCH 1/2] docs: fix types and measureElement reference in Virtualizer docs for accuracy and consistency --- docs/api/virtualizer.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/api/virtualizer.md b/docs/api/virtualizer.md index 79d2df1b..bd402dce 100644 --- a/docs/api/virtualizer.md +++ b/docs/api/virtualizer.md @@ -23,7 +23,7 @@ The total number of items to virtualize. ### `getScrollElement` ```tsx -getScrollElement: () => TScrollElement +getScrollElement: () => TScrollElement | null ``` A function that returns the scrollable element for the virtualizer. It may return null if the element is not available yet. @@ -36,7 +36,7 @@ estimateSize: (index: number) => number > 🧠 If you are dynamically measuring your elements, it's recommended to estimate the largest possible size (width/height, within comfort) of your items. This will ensure features like smooth-scrolling will have a better chance at working correctly. -This function is passed the index of each item and should return the actual size (or estimated size if you will be dynamically measuring items with `virtualItem.measureElement`) for each item. This measurement should return either the width or height depending on the orientation of your virtualizer. +This function is passed the index of each item and should return the actual size (or estimated size if you will be dynamically measuring items with `Virtualizer.measureElement`) for each item. This measurement should return either the width or height depending on the orientation of your virtualizer. ## Optional Options @@ -149,7 +149,7 @@ This function receives visible range indexes and should return array of indexes ### `scrollToFn` ```tsx -scrollToFn?: ( +scrollToFn: ( offset: number, options: { adjustments?: number; behavior?: 'auto' | 'smooth' }, instance: Virtualizer, @@ -182,7 +182,7 @@ An optional function that if provided is called when the scrollElement changes a ```tsx observeElementOffset: ( instance: Virtualizer, - cb: (offset: number) => void, + cb: (offset: number, isScrolling: boolean) => void, ) => void | (() => void) ``` @@ -227,7 +227,7 @@ This option allows you to set the spacing between items in the virtualized list. ### `lanes` ```tsx -lanes: number +lanes?: number ``` The number of lanes the list is divided into (aka columns for vertical lists and rows for horizontal lists). @@ -235,7 +235,7 @@ The number of lanes the list is divided into (aka columns for vertical lists and ### `isScrollingResetDelay` ```tsx -isScrollingResetDelay: number +isScrollingResetDelay?: number ``` This option allows you to specify the duration to wait after the last scroll event before resetting the isScrolling instance property. The default value is 150 milliseconds. @@ -245,7 +245,7 @@ The implementation of this option is driven by the need for a reliable mechanism ### `useScrollendEvent` ```tsx -useScrollendEvent: boolean +useScrollendEvent?: boolean ``` Determines whether to use the native scrollend event to detect when scrolling has stopped. If set to false, a debounced fallback is used to reset the isScrolling instance property after isScrollingResetDelay milliseconds. The default value is `false`. @@ -255,7 +255,7 @@ The implementation of this option is driven by the need for a reliable mechanism ### `isRtl` ```tsx -isRtl: boolean +isRtl?: boolean ``` Whether to invert horizontal scrolling to support right-to-left language locales. @@ -263,7 +263,7 @@ Whether to invert horizontal scrolling to support right-to-left language locales ### `useAnimationFrameWithResizeObserver` ```tsx -useAnimationFrameWithResizeObserver: boolean +useAnimationFrameWithResizeObserver?: boolean ``` This option enables wrapping ResizeObserver measurements in requestAnimationFrame for smoother updates and reduced layout thrashing. The default value is `false`. @@ -353,7 +353,7 @@ Resets any prev item measurements. ### `measureElement` ```tsx -measureElement: (el: TItemElement | null) => void +measureElement: (el: TItemElement | null | undefined) => void ``` Measures the element using your configured `measureElement` virtualizer option. You are responsible for calling this in your virtualizer markup when the component is rendered (eg. using something like React's ref callback prop) also adding `data-index` @@ -384,7 +384,7 @@ You can also use this method with a throttled ResizeObserver instead of `Virtual ### `scrollRect` ```tsx -scrollRect: Rect +scrollRect: Rect | null ``` Current `Rect` of the scroll element. @@ -416,7 +416,7 @@ This option indicates the direction of scrolling, with possible values being 'fo ### `scrollOffset` ```tsx -scrollOffset: number +scrollOffset: number | null ``` This option represents the current scroll position along the scrolling axis. It is measured in pixels from the starting point of the scrollable area. From 62e75a72741f3ee73a7d19e3b59a327b439ab1eb Mon Sep 17 00:00:00 2001 From: wo-o29 Date: Sun, 31 Aug 2025 11:24:12 +0900 Subject: [PATCH 2/2] docs: fix typo --- docs/api/virtualizer.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/virtualizer.md b/docs/api/virtualizer.md index bd402dce..2bac4fbc 100644 --- a/docs/api/virtualizer.md +++ b/docs/api/virtualizer.md @@ -375,7 +375,7 @@ By default the `measureElement` virtualizer option is configured to measure elem resizeItem: (index: number, size: number) => void ``` -Change the virtualized item's size manually. Use this function to manually set the size calculated for this index. Useful in occations when using some custom morphing transition and you know the morphed item's size beforehand. +Change the virtualized item's size manually. Use this function to manually set the size calculated for this index. Useful in occasions when using some custom morphing transition and you know the morphed item's size beforehand. You can also use this method with a throttled ResizeObserver instead of `Virtualizer.measureElement` to reduce re-rendering.