@tanstack/react-virtual 3.0.0-alpha.0 → 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +1 -18
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
- package/build/cjs/react-virtual/src/index.js +90 -0
- package/build/cjs/react-virtual/src/index.js.map +1 -0
- package/build/cjs/virtual-core/build/esm/index.js +565 -0
- package/build/cjs/virtual-core/build/esm/index.js.map +1 -0
- package/build/esm/index.js +432 -350
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +24 -119
- package/build/types/react-virtual/src/index.d.ts +4 -0
- package/build/types/virtual-core/src/utils.d.ts +7 -0
- package/build/umd/index.development.js +443 -352
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +11 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +16 -17
- package/src/index.tsx +66 -386
- package/build/cjs/packages/react-virtual/src/index.js +0 -371
- package/build/cjs/packages/react-virtual/src/index.js.map +0 -1
- package/build/cjs/packages/react-virtual/src/useIsomorphicLayoutEffect.js +0 -40
- package/build/cjs/packages/react-virtual/src/useIsomorphicLayoutEffect.js.map +0 -1
- package/build/cjs/packages/react-virtual/src/useRect.js +0 -85
- package/build/cjs/packages/react-virtual/src/useRect.js.map +0 -1
- package/build/types/index.d.ts +0 -53
- package/build/types/useIsomorphicLayoutEffect.d.ts +0 -2
- package/build/types/useRect.d.ts +0 -6
- package/src/useIsomorphicLayoutEffect.ts +0 -4
- package/src/useRect.ts +0 -58
package/src/useRect.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import observeRect from '@reach/observe-rect'
|
|
3
|
-
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect'
|
|
4
|
-
|
|
5
|
-
export interface Rect {
|
|
6
|
-
width: number
|
|
7
|
-
height: number
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function rectReducer(state: Rect, action: { rect: Rect }) {
|
|
11
|
-
const rect = action.rect
|
|
12
|
-
if (state.height !== rect.height || state.width !== rect.width) {
|
|
13
|
-
return rect
|
|
14
|
-
}
|
|
15
|
-
return state
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const useRect = <T extends HTMLElement>(
|
|
19
|
-
nodeRef: React.RefObject<T>,
|
|
20
|
-
initialRect: Rect = { width: 0, height: 0 },
|
|
21
|
-
) => {
|
|
22
|
-
const [element, setElement] = React.useState(nodeRef.current)
|
|
23
|
-
const [rect, dispatch] = React.useReducer(rectReducer, initialRect)
|
|
24
|
-
|
|
25
|
-
const initialRectSet = React.useRef(false)
|
|
26
|
-
|
|
27
|
-
useIsomorphicLayoutEffect(() => {
|
|
28
|
-
if (nodeRef.current !== element) {
|
|
29
|
-
setElement(nodeRef.current)
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
useIsomorphicLayoutEffect(() => {
|
|
34
|
-
if (element && !initialRectSet.current) {
|
|
35
|
-
initialRectSet.current = true
|
|
36
|
-
const rect = element.getBoundingClientRect()
|
|
37
|
-
dispatch({ rect })
|
|
38
|
-
}
|
|
39
|
-
}, [element])
|
|
40
|
-
|
|
41
|
-
React.useEffect(() => {
|
|
42
|
-
if (!element) {
|
|
43
|
-
return
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const observer = observeRect(element, (rect) => {
|
|
47
|
-
dispatch({ rect })
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
observer.observe()
|
|
51
|
-
|
|
52
|
-
return () => {
|
|
53
|
-
observer.unobserve()
|
|
54
|
-
}
|
|
55
|
-
}, [element])
|
|
56
|
-
|
|
57
|
-
return rect
|
|
58
|
-
}
|