UNPKG

react-location-devtools

Version:

See https://react-location.tanstack.com/tools/devtools

59 lines (45 loc) 1.59 kB
/** * react-location-devtools * * Copyright (c) TanStack * * This source code is licensed under the MIT license found in the * LICENSE.md file in the root directory of this source tree. * * @license MIT */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var React = require('react'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var React__default = /*#__PURE__*/_interopDefaultLegacy(React); function useMediaQuery(query) { // Keep track of the preference in state, start with the current match var _React$useState = React__default["default"].useState(function () { if (typeof window !== 'undefined') { return window.matchMedia && window.matchMedia(query).matches; } }), isMatch = _React$useState[0], setIsMatch = _React$useState[1]; // Watch for changes React__default["default"].useEffect(function () { if (typeof window !== 'undefined') { if (!window.matchMedia) { return; } // Create a matcher var matcher = window.matchMedia(query); // Create our handler var onChange = function onChange(_ref) { var matches = _ref.matches; return setIsMatch(matches); }; // Listen for changes matcher.addListener(onChange); return function () { // Stop listening for changes matcher.removeListener(onChange); }; } }, [isMatch, query, setIsMatch]); return isMatch; } exports["default"] = useMediaQuery; //# sourceMappingURL=useMediaQuery.js.map