devvsakib / power-the-web

Open-source project. Hacktoberfest2022, Diversion2k23 - Clone this repo and explore all the projects
https://ptwa.vercel.app
MIT License
75 stars 126 forks source link

Optimized the useWindow custom hook for performance #367

Closed nelsonuprety1 closed 1 year ago

nelsonuprety1 commented 1 year ago

I've made some changes to optimize the code that handles window size changes. Here's what I've done:

I removed the repeated logic for getting the window size and instead used a reusable function to get the size once and store it in a variable. I added a debouncing mechanism to the resize event listener to prevent the function from being called too frequently.

I used requestAnimationFrame to throttle the resize event and only call the function once per animation frame. These changes should improve performance and reduce the number of unnecessary function calls.

Let me know if you have any questions or concerns.

vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ptw ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 8, 2023 3:44pm