'How to use 2 addEventListener inside 1 useEffect in React

code react

I want to make this code shorter, what is the best way to do it , using best practices.



Solution 1:[1]

const [dims, setDims] = useState({})

useEffect(() => window.addEventListener('resize', () => {
  setDims({height: window.innerHeight, width: window.innerWidth})
}))

P.S. Put your code in questions with text, not with an image

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vladyslav Yukhanov