useScreenWidth

The solution for “useScreenWidth” can be found here. The following code will assist you in solving the problem.

import { useEffect, useState } from ’react’;

export function useScreenWidth(): number {
const [width, setWidth] = useState(window.innerWidth);

useEffect(() => {
const handler = (event: any) => {
setWidth(event.target.innerWidth);
};

window.addEventListener(’resize’, handler);

return () => {
window.removeEventListener(’resize’, handler);
};
}, []);

return width;
}

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in