virtual-scroller 1.12.1 → 1.12.3
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/CHANGELOG.md +9 -0
- package/CODE_OF_CONDUCT.md +78 -0
- package/README.md +75 -10
- package/bundle/virtual-scroller-dom.js +1 -1
- package/bundle/virtual-scroller-dom.js.map +1 -1
- package/bundle/virtual-scroller-react.js +1 -1
- package/bundle/virtual-scroller-react.js.map +1 -1
- package/bundle/virtual-scroller.js +1 -1
- package/bundle/virtual-scroller.js.map +1 -1
- package/commonjs/ItemHeights.js +1 -1
- package/commonjs/ItemHeights.js.map +1 -1
- package/commonjs/Layout.js +1 -1
- package/commonjs/Layout.js.map +1 -1
- package/commonjs/Scroll.js +2 -1
- package/commonjs/Scroll.js.map +1 -1
- package/commonjs/VirtualScroller.js +62 -23
- package/commonjs/VirtualScroller.js.map +1 -1
- package/commonjs/VirtualScroller.layout.js +16 -10
- package/commonjs/VirtualScroller.layout.js.map +1 -1
- package/commonjs/VirtualScroller.onRender.js +2 -2
- package/commonjs/VirtualScroller.onRender.js.map +1 -1
- package/commonjs/getVerticalSpacing.js +5 -2
- package/commonjs/getVerticalSpacing.js.map +1 -1
- package/commonjs/react/VirtualScroller.js +3 -0
- package/commonjs/react/VirtualScroller.js.map +1 -1
- package/commonjs/react/useEffectDontMountTwiceInStrictMode.js +83 -0
- package/commonjs/react/useEffectDontMountTwiceInStrictMode.js.map +1 -0
- package/commonjs/react/useInsertionEffectDontMountTwiceInStrictMode.js +20 -0
- package/commonjs/react/useInsertionEffectDontMountTwiceInStrictMode.js.map +1 -0
- package/commonjs/react/useLayoutEffectDontMountTwiceInStrictMode.js +20 -0
- package/commonjs/react/useLayoutEffectDontMountTwiceInStrictMode.js.map +1 -0
- package/commonjs/react/useState.js +13 -7
- package/commonjs/react/useState.js.map +1 -1
- package/commonjs/react/useStateNoStaleBug.js +59 -0
- package/commonjs/react/useStateNoStaleBug.js.map +1 -0
- package/modules/ItemHeights.js +1 -1
- package/modules/ItemHeights.js.map +1 -1
- package/modules/Layout.js +1 -1
- package/modules/Layout.js.map +1 -1
- package/modules/Scroll.js +2 -1
- package/modules/Scroll.js.map +1 -1
- package/modules/VirtualScroller.js +62 -23
- package/modules/VirtualScroller.js.map +1 -1
- package/modules/VirtualScroller.layout.js +16 -10
- package/modules/VirtualScroller.layout.js.map +1 -1
- package/modules/VirtualScroller.onRender.js +2 -2
- package/modules/VirtualScroller.onRender.js.map +1 -1
- package/modules/getVerticalSpacing.js +5 -2
- package/modules/getVerticalSpacing.js.map +1 -1
- package/modules/react/VirtualScroller.js +3 -1
- package/modules/react/VirtualScroller.js.map +1 -1
- package/modules/react/useEffectDontMountTwiceInStrictMode.js +75 -0
- package/modules/react/useEffectDontMountTwiceInStrictMode.js.map +1 -0
- package/modules/react/useInsertionEffectDontMountTwiceInStrictMode.js +9 -0
- package/modules/react/useInsertionEffectDontMountTwiceInStrictMode.js.map +1 -0
- package/modules/react/useLayoutEffectDontMountTwiceInStrictMode.js +9 -0
- package/modules/react/useLayoutEffectDontMountTwiceInStrictMode.js.map +1 -0
- package/modules/react/useState.js +11 -8
- package/modules/react/useState.js.map +1 -1
- package/modules/react/useStateNoStaleBug.js +51 -0
- package/modules/react/useStateNoStaleBug.js.map +1 -0
- package/package.json +1 -1
- package/source/ItemHeights.js +1 -1
- package/source/Layout.js +1 -1
- package/source/Scroll.js +1 -0
- package/source/VirtualScroller.js +61 -21
- package/source/VirtualScroller.layout.js +14 -8
- package/source/VirtualScroller.onRender.js +2 -2
- package/source/getVerticalSpacing.js +5 -2
- package/source/react/VirtualScroller.js +3 -0
- package/source/react/useEffectDontMountTwiceInStrictMode.js +68 -0
- package/source/react/useInsertionEffectDontMountTwiceInStrictMode.js +10 -0
- package/source/react/useLayoutEffectDontMountTwiceInStrictMode.js +10 -0
- package/source/react/useState.js +8 -5
- package/source/react/useStateNoStaleBug.js +35 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useRef, useState, useCallback } from 'react'
|
|
2
|
+
|
|
3
|
+
// This hook fixes any weird intermediate inconsistent/invalid/stale state values.
|
|
4
|
+
// https://github.com/facebook/react/issues/25023#issuecomment-1480463544
|
|
5
|
+
export default function useStateNoStaleBug(initialState) {
|
|
6
|
+
// const latestValidState = useRef(initialState)
|
|
7
|
+
const latestWrittenState = useRef(initialState)
|
|
8
|
+
const [_state, _setState] = useState(initialState)
|
|
9
|
+
|
|
10
|
+
// Instead of dealing with a potentially out-of-sync (stale) state value,
|
|
11
|
+
// simply use the correct latest one.
|
|
12
|
+
const state = latestWrittenState.current
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
let state
|
|
16
|
+
if (_state === latestWrittenState.current) {
|
|
17
|
+
state = _state
|
|
18
|
+
latestValidState.current = _state
|
|
19
|
+
} else {
|
|
20
|
+
// React bug detected: an out-of-sync (stale) state value received.
|
|
21
|
+
// Ignore the out-of-sync (stale) state value.
|
|
22
|
+
state = latestValidState.current
|
|
23
|
+
}
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
const setState = useCallback((newState) => {
|
|
27
|
+
if (typeof newState === 'function') {
|
|
28
|
+
throw new Error('Function argument of `setState()` function is not supported by this hook')
|
|
29
|
+
}
|
|
30
|
+
latestWrittenState.current = newState
|
|
31
|
+
_setState(newState)
|
|
32
|
+
}, [])
|
|
33
|
+
|
|
34
|
+
return [state, setState]
|
|
35
|
+
}
|