PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.15.3
GiveWP – Donation Plugin and Fundraising Platform v4.15.3
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
give / src / DonorDashboards / resources / js / app / hooks / index.js

index.js in GiveWP – Donation Plugin and Fundraising Platform 4.15.3, at src/DonorDashboards/resources/js/app/hooks/index.js

40 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import {useState, useEffect} from 'react';
2 import {useSelector} from 'react-redux';
3
4 // From use hooks, see: https://usehooks.com/useWindowSize/
5
6 export const useAccentColor = () => {
7 return useSelector((state) => state.accentColor);
8 };
9
10 export const useWindowSize = () => {
11 // Initialize state with undefined width/height so server and client renders match
12 // Learn more here: https://joshwcomeau.com/react/the-perils-of-rehydration/
13 const [windowSize, setWindowSize] = useState({
14 width: undefined,
15 height: undefined,
16 });
17
18 useEffect(() => {
19 // Handler to call on window resize
20 function handleResize() {
21 // Set window width/height to state
22 setWindowSize({
23 width: window.top.innerWidth,
24 height: window.top.innerHeight,
25 });
26 }
27
28 // Add event listener
29 window.top.addEventListener('resize', handleResize);
30
31 // Call handler right away so state gets updated with initial window size
32 handleResize();
33
34 // Remove event listener on cleanup
35 return () => window.top.removeEventListener('resize', handleResize);
36 }, []); // Empty array ensures that effect is only run on mount
37
38 return windowSize;
39 };
40