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 _useScreenWakeLock_ hook to detect if WakeLock API is available and renders informations about it. It has a button also, to acquire and release a WakeLock.
5
+
*/
6
+
exportconstUseScreenWakeLock=()=>{
7
+
const[info,acquire,release]=useScreenWakeLock();
8
+
9
+
return<>
10
+
<p>WakeLock API supported: {info.isSupported ? "Yes" : "No"}</p>
11
+
<p>WakeLock type: {info.type ? info.type : "WakeLock not found."}</p>
> The component has _three internal string states_ and renders three input fields and three components that receive one state each. These three components have an object as internal state with two properties _loading_, initially set to __true__, and _friends_ which is an initially empty array.
112
-
> Based on the _user_ prop they receive, they set the _loading_ property of the internal state to __true__ and invoke a _serverAPI_ function that simulates a backend call and returns a list of names filtered by the passed _prop_. This list values the _friends_ property of the internal state and this list together with the passed _user_ prop are rendered:
112
+
> Based on the _user_ prop they receive, they set the _loading_ property of the internal state to __true__ and invoke a _serverAPI_ function that simulates a backend call and returns a list of names filtered by the passed _prop_. This list values the _friends_ property of the internal state and this list together with the passed _user_ prop are rendered:
113
113
> - The _Without useDerivedState_ component uses the _useState_ and _useEffect_ hooks to implement this logic.
114
114
> - The _With useDerivedState_ component uses the _useDerivedState_ hook and the _useEffect_.
115
115
> - The _With useDerivedStateAndCompute_ component uses the _useDerivedState_ hook and the optional third parameter to implement all logic.
> The component without _useDerivedState_ hook is rendered one more time every time its _prop_ changes while the other two have the same number of renders.
120
120
>
121
-
> Furthermore, if you debug the code you can see how in the first component there is no synchronization in the updating of the values since in a first render the rendered _prop_ user is updated and in a second render the writing `loading` is rendered instead of the list of names.
121
+
> Furthermore, if you debug the code you can see how in the first component there is no synchronization in the updating of the values since in a first render the rendered _prop_ user is updated and in a second render the writing `loading` is rendered instead of the list of names.
> The component uses _useScreenWakeLock_ hook to detect if WakeLock API is available and renders informations about it. It has a button also, to acquire and release a WakeLock.
* **`useScreenWakeLock`**: Hook to use [Screen Wake Lock API](https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API).
6
+
* @param {(evt?:Event)=>void} [onRelease] - function that will be executed on release event.
7
+
* @returns {[{isSupported: boolean, type: "screen"|null, isActive: boolean|null}, ()=>Promise<void>, ()=>Promise<void>]} result - An array with three element:
8
+
* - 1. __info__: object with these properties:
9
+
* - _isSupported_: returns a boolean to know if API is available.
10
+
* - _type_: return a string representation of the currently acquired WakeLock type.
11
+
* - _isActive_: returns a boolean indicating whether the WakeLockSentinel has been activated.
12
+
* - 2. __acquire__: function to request a WakeLock.
13
+
* - 3. __release__: function to release a WakeLock.
0 commit comments