react keep screen on

Solutions on MaxInterview for react keep screen on by the best coders in the world

showing results for - "react keep screen on"
Nikki
18 Apr 2019
1// Download the nosleep.js bundle
2// npm install nosleep.js
3
4// Import and declare NoSleep
5// REACT CODE STARTS HERE
6import React from 'react';
7import NoSleep from 'nosleep.js';
8
9var noSleep = new NoSleep();
10
11const WakeButton = () => {
12return(
13<div>
14{/* Enable noSleep by wrapping this code in a user input event handler (such as a button) */}
15<button onClick={() => {
16	document.addEventListener('click', function enableNoSleep() {
17	document.removeEventListener('click', enableNoSleep, false);
18	noSleep.enable();
19	}, false);
20}}>Enable noSleep</ button>
21{/* Disable noSleep */}
22<button onClick={() => {
23	noSleep.disable();
24	}}>Disable noSleep</ button>
25</div>
26)
27}
28
29export default WakeButton;