Comparing version 3.8.3 to 3.8.4
import { __read } from "tslib"; | ||
import { useEffect, useState } from 'react'; | ||
import useMemoizedFn from '../useMemoizedFn'; | ||
import isBrowser from '../utils/isBrowser'; | ||
export var ThemeMode; | ||
@@ -10,7 +11,10 @@ (function (ThemeMode) { | ||
})(ThemeMode || (ThemeMode = {})); | ||
var matchMedia = window.matchMedia('(prefers-color-scheme: dark)'); | ||
function useCurrentTheme() { | ||
var matchMedia = isBrowser ? window.matchMedia('(prefers-color-scheme: dark)') : undefined; | ||
var _a = __read(useState(function () { | ||
var init = matchMedia.matches ? ThemeMode.DARK : ThemeMode.LIGHT; | ||
return init; | ||
if (isBrowser) { | ||
return (matchMedia === null || matchMedia === void 0 ? void 0 : matchMedia.matches) ? ThemeMode.DARK : ThemeMode.LIGHT; | ||
} else { | ||
return ThemeMode.LIGHT; | ||
} | ||
}), 2), | ||
@@ -27,5 +31,5 @@ theme = _a[0], | ||
}; | ||
matchMedia.addEventListener('change', onThemeChange); | ||
matchMedia === null || matchMedia === void 0 ? void 0 : matchMedia.addEventListener('change', onThemeChange); | ||
return function () { | ||
matchMedia.removeEventListener('change', onThemeChange); | ||
matchMedia === null || matchMedia === void 0 ? void 0 : matchMedia.removeEventListener('change', onThemeChange); | ||
}; | ||
@@ -32,0 +36,0 @@ }, []); |
@@ -12,2 +12,3 @@ "use strict"; | ||
var _useMemoizedFn = _interopRequireDefault(require("../useMemoizedFn")); | ||
var _isBrowser = _interopRequireDefault(require("../utils/isBrowser")); | ||
var ThemeMode; | ||
@@ -19,7 +20,10 @@ (function (ThemeMode) { | ||
})(ThemeMode || (exports.ThemeMode = ThemeMode = {})); | ||
var matchMedia = window.matchMedia('(prefers-color-scheme: dark)'); | ||
function useCurrentTheme() { | ||
var matchMedia = _isBrowser["default"] ? window.matchMedia('(prefers-color-scheme: dark)') : undefined; | ||
var _a = (0, _tslib.__read)((0, _react.useState)(function () { | ||
var init = matchMedia.matches ? ThemeMode.DARK : ThemeMode.LIGHT; | ||
return init; | ||
if (_isBrowser["default"]) { | ||
return (matchMedia === null || matchMedia === void 0 ? void 0 : matchMedia.matches) ? ThemeMode.DARK : ThemeMode.LIGHT; | ||
} else { | ||
return ThemeMode.LIGHT; | ||
} | ||
}), 2), | ||
@@ -36,5 +40,5 @@ theme = _a[0], | ||
}; | ||
matchMedia.addEventListener('change', onThemeChange); | ||
matchMedia === null || matchMedia === void 0 ? void 0 : matchMedia.addEventListener('change', onThemeChange); | ||
return function () { | ||
matchMedia.removeEventListener('change', onThemeChange); | ||
matchMedia === null || matchMedia === void 0 ? void 0 : matchMedia.removeEventListener('change', onThemeChange); | ||
}; | ||
@@ -41,0 +45,0 @@ }, []); |
{ | ||
"name": "ahooks", | ||
"version": "3.8.3", | ||
"version": "3.8.4", | ||
"description": "react hooks library", | ||
@@ -5,0 +5,0 @@ "keywords": ["ahooks", "umi hooks", "react hooks"], |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
596928
13948