"use strict";

exports.__esModule = true;
exports.default = useWidth;

var _react = require("react");

/**
 * Check the screen width
 * @param {number} initialWidth - Define the initial width number to consider if the screen flics
 */
function useWidth(initialWidth = 0) {
  // width window
  const [width, setWidth] = (0, _react.useState)(initialWidth);

  function handleWindowSizeChange() {
    setWidth(window.innerWidth);
  }

  (0, _react.useEffect)(() => {
    handleWindowSizeChange();
    window.addEventListener("resize", handleWindowSizeChange);
    window.addEventListener("DOMContentLoaded", handleWindowSizeChange);
    return () => {
      window.removeEventListener("resize", handleWindowSizeChange);
      window.removeEventListener("DOMContentLoaded", handleWindowSizeChange);
    };
  }, [handleWindowSizeChange, width]); // end width hook

  return width;
}

module.exports = exports.default;