Write a custom hook useWindowDimensions that returns an object with two properties: the current width and height of the window. The hook should update the dimensions whenever the window is resized. Please see the example below for the required return object.
We have already written some starting code for you.
Make use of the built-in useState and useEffect hooks to track the window dimensions and update them when the window is resized.
The useEffect hook should have an event listener to listen for a resize event and call the setWindowDimensions function to update the state with the new dimensions.
Remember to cleanup the event listener by returning a function from the useEffect hook that removes the listener, this helps prevent memory leaks in your application.
Tests