@folklore/hooks 0.0.64 → 0.0.65
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/dist/cjs.js +10 -5
- package/dist/es.js +10 -5
- package/package.json +2 -2
package/dist/cjs.js
CHANGED
|
@@ -1742,17 +1742,19 @@ function useWindowSize() {
|
|
|
1742
1742
|
onChange = null
|
|
1743
1743
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1744
1744
|
const [size, setSize] = react.useState(currentSize);
|
|
1745
|
+
const sizeRef = react.useRef(size);
|
|
1745
1746
|
const updateSize = react.useCallback(() => {
|
|
1746
1747
|
const newSize = getWindowSize();
|
|
1747
1748
|
if (currentSize.width !== newSize.width || currentSize.height !== newSize.height) {
|
|
1748
1749
|
currentSize = newSize;
|
|
1749
1750
|
}
|
|
1750
|
-
if (
|
|
1751
|
+
if (sizeRef.current.width !== newSize.width || sizeRef.current.height !== newSize.height) {
|
|
1752
|
+
sizeRef.current = newSize;
|
|
1751
1753
|
setSize(newSize);
|
|
1752
1754
|
return newSize;
|
|
1753
1755
|
}
|
|
1754
1756
|
return null;
|
|
1755
|
-
}, [
|
|
1757
|
+
}, [setSize]);
|
|
1756
1758
|
const onResize = react.useCallback(() => {
|
|
1757
1759
|
const newSize = updateSize();
|
|
1758
1760
|
if (newSize !== null && onChange !== null) {
|
|
@@ -1825,18 +1827,21 @@ const getWindowScroll = () => ({
|
|
|
1825
1827
|
x: typeof window !== 'undefined' ? window.scrollX || 0 : 0,
|
|
1826
1828
|
y: typeof window !== 'undefined' ? window.scrollY || 0 : 0
|
|
1827
1829
|
});
|
|
1828
|
-
|
|
1830
|
+
let currentScroll = getWindowScroll();
|
|
1829
1831
|
function useWindowScroll() {
|
|
1830
1832
|
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1831
1833
|
const {
|
|
1832
1834
|
onChange = null
|
|
1833
1835
|
} = opts;
|
|
1834
1836
|
const [scroll, setScroll] = react.useState(currentScroll);
|
|
1837
|
+
const scrollRef = react.useRef(scroll);
|
|
1835
1838
|
const updateScroll = react.useCallback(() => {
|
|
1836
1839
|
const newScroll = getWindowScroll();
|
|
1837
1840
|
if (currentScroll.x !== newScroll.x || currentScroll.y !== newScroll.y) {
|
|
1838
|
-
currentScroll
|
|
1839
|
-
|
|
1841
|
+
currentScroll = newScroll;
|
|
1842
|
+
}
|
|
1843
|
+
if (scrollRef.current.x !== newScroll.x || scrollRef.current.y !== newScroll.y) {
|
|
1844
|
+
scrollRef.current = newScroll;
|
|
1840
1845
|
setScroll(newScroll);
|
|
1841
1846
|
return newScroll;
|
|
1842
1847
|
}
|
package/dist/es.js
CHANGED
|
@@ -1731,17 +1731,19 @@ function useWindowSize() {
|
|
|
1731
1731
|
onChange = null
|
|
1732
1732
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1733
1733
|
const [size, setSize] = useState(currentSize);
|
|
1734
|
+
const sizeRef = useRef(size);
|
|
1734
1735
|
const updateSize = useCallback(() => {
|
|
1735
1736
|
const newSize = getWindowSize();
|
|
1736
1737
|
if (currentSize.width !== newSize.width || currentSize.height !== newSize.height) {
|
|
1737
1738
|
currentSize = newSize;
|
|
1738
1739
|
}
|
|
1739
|
-
if (
|
|
1740
|
+
if (sizeRef.current.width !== newSize.width || sizeRef.current.height !== newSize.height) {
|
|
1741
|
+
sizeRef.current = newSize;
|
|
1740
1742
|
setSize(newSize);
|
|
1741
1743
|
return newSize;
|
|
1742
1744
|
}
|
|
1743
1745
|
return null;
|
|
1744
|
-
}, [
|
|
1746
|
+
}, [setSize]);
|
|
1745
1747
|
const onResize = useCallback(() => {
|
|
1746
1748
|
const newSize = updateSize();
|
|
1747
1749
|
if (newSize !== null && onChange !== null) {
|
|
@@ -1814,18 +1816,21 @@ const getWindowScroll = () => ({
|
|
|
1814
1816
|
x: typeof window !== 'undefined' ? window.scrollX || 0 : 0,
|
|
1815
1817
|
y: typeof window !== 'undefined' ? window.scrollY || 0 : 0
|
|
1816
1818
|
});
|
|
1817
|
-
|
|
1819
|
+
let currentScroll = getWindowScroll();
|
|
1818
1820
|
function useWindowScroll() {
|
|
1819
1821
|
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1820
1822
|
const {
|
|
1821
1823
|
onChange = null
|
|
1822
1824
|
} = opts;
|
|
1823
1825
|
const [scroll, setScroll] = useState(currentScroll);
|
|
1826
|
+
const scrollRef = useRef(scroll);
|
|
1824
1827
|
const updateScroll = useCallback(() => {
|
|
1825
1828
|
const newScroll = getWindowScroll();
|
|
1826
1829
|
if (currentScroll.x !== newScroll.x || currentScroll.y !== newScroll.y) {
|
|
1827
|
-
currentScroll
|
|
1828
|
-
|
|
1830
|
+
currentScroll = newScroll;
|
|
1831
|
+
}
|
|
1832
|
+
if (scrollRef.current.x !== newScroll.x || scrollRef.current.y !== newScroll.y) {
|
|
1833
|
+
scrollRef.current = newScroll;
|
|
1829
1834
|
setScroll(newScroll);
|
|
1830
1835
|
return newScroll;
|
|
1831
1836
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@folklore/hooks",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.65",
|
|
4
4
|
"description": "React hooks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "68405a5d9870a928ba8a5aff525ea835fa01b552",
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@folklore/events": "^0.0.5",
|
|
55
55
|
"@folklore/services": "^0.1.41",
|