Skip to content

Commit

Permalink
feat: Add measure method, issue #31 (#55)
Browse files Browse the repository at this point in the history
* feat: Add measure method, issue #31

* refactor: measure method

Reduce roundtrips

* Fix: virtualItems should not depend on state

* Fix: remove eslint-disable-next-line react-hooks/exhaustive-deps

Co-authored-by: David Wincent <[email protected]>
Co-authored-by: David Wincent <[email protected]>
  • Loading branch information
3 people authored Mar 5, 2021
1 parent 7ad4628 commit ea6b541
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export function useVirtual({

const [measuredCache, setMeasuredCache] = React.useState({})

const measure = React.useCallback(
() => setMeasuredCache({}),
[]
)

const measurements = React.useMemo(() => {
const measurements = []
for (let i = 0; i < size; i++) {
Expand Down Expand Up @@ -215,6 +220,7 @@ export function useVirtual({
totalSize,
scrollToOffset,
scrollToIndex,
measure,
}
}

Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ declare function useVirtual<T>(options: {
totalSize: number
scrollToOffset: (index: number, options?: ScrollToOffsetOptions) => void
scrollToIndex: (index: number, options?: ScrollToIndexOptions) => void
measure: () => void
}

export { useVirtual }

0 comments on commit ea6b541

Please sign in to comment.