You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> The component uses _useColorScheme_ with these properties:
24
+
> -_defaultValue_: __"mediaQuery"__, so it read color-scheme with media query.
25
+
> -_returnValue_: __true__, so it returns current value.
26
+
> -_getter_: a function that returns value from sessionStorage item with key "color-scheme".
27
+
> -_setter_: a function that save current value to sessionStorage item with key "color-scheme".
28
+
> The component renders a div with a class container that changes border and text colors by color-scheme selected and a button to manually change value.
initial value if _getter_ function isn't present or isn't return a valid value. It can be _dark_ _light_ or _mediaQuery_ which means that must to be used media query prefers-color-scheme to detect initial value.
an optional function used to initialize current value. For example, it can be useful for reading the value from an attribute of an html file or from localStorage.
44
+
> - __param.setter?__: _("dark"|"light")=>void_
45
+
an optional function, which should work in conjunction with the _getter_ function, to run when the color scheme changes to save the value for future runs.
46
+
> - __param.returnValue__: _boolean_
47
+
if true returns only a function to manually change the color scheme value.
48
+
>
49
+
50
+
> ### Returns
51
+
>
52
+
> __result__: if _returnValue_ is true, _result_ is the function to update color scheme value, otherwise is an array where first element is current value and second element is the function to update value.
* **`useColorScheme`**: Hook to handle ColorScheme.
6
+
* @param {Object} param
7
+
* @param {"dark"|"light"|"mediaQuery"} param.defaultValue - initial value if _getter_ function isn't present or isn't return a valid value. It can be _dark_ _light_ or _mediaQuery_ which means that must to be used media query prefers-color-scheme to detect initial value.
8
+
* @param {()=>"dark"|"light"|null|undefined} [param.getter] - an optional function used to initialize current value. For example, it can be useful for reading the value from an attribute of an html file or from localStorage.
9
+
* @param {("dark"|"light")=>void} [param.setter] - an optional function, which should work in conjunction with the _getter_ function, to run when the color scheme changes to save the value for future runs.
10
+
* @param {boolean} param.returnValue - if true returns only a function to manually change the color scheme value.
11
+
* @returns {["dark"|"light", (schema:"dark"|"light") => void] | (schema:"dark"|"light") => void} result - if _returnValue_ is true, _result_ is the function to update color scheme value, otherwise is an array where first element is current value and second element is the function to update value.
Copy file name to clipboardExpand all lines: packages/react-tools/src/hooks/useMediaQuery.ts
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
import{useCallback,useRef}from"react"
1
+
import{useCallback,useMemo,useRef}from"react"
2
2
import{useSyncExternalStore}from"."
3
3
4
4
/**
@@ -8,13 +8,13 @@ import { useSyncExternalStore } from "."
8
8
* @returns {{matches: boolean, media: string}} result - object with __matches__, boolean value that returns true if the document currently matches the media query, __media__, string that represents media query.
0 commit comments