Answers for "react keep screen on"

0

react keep screen on

// Download the nosleep.js bundle
// npm install nosleep.js

// Import and declare NoSleep
// REACT CODE STARTS HERE
import React from 'react';
import NoSleep from 'nosleep.js';

var noSleep = new NoSleep();

const WakeButton = () => {
return(
<div>
{/* Enable noSleep by wrapping this code in a user input event handler (such as a button) */}
<button onClick={() => {
	document.addEventListener('click', function enableNoSleep() {
	document.removeEventListener('click', enableNoSleep, false);
	noSleep.enable();
	}, false);
}}>Enable noSleep</ button>
{/* Disable noSleep */}
<button onClick={() => {
	noSleep.disable();
	}}>Disable noSleep</ button>
</div>
)
}

export default WakeButton;
Posted by: Guest on December-22-2020

Code answers related to "react keep screen on"

Code answers related to "Javascript"

Browse Popular Code Answers by Language