use window hooks it is hooks for reactjs and nextjs apps
This React TypeScript library provides a set of powerful hooks and components for managing and handling various aspects of responsive design in your applications.
A lightweight React hook that tells whether a component is still mounted.