Skip to content

Instantly share code, notes, and snippets.

@takaki
Created November 9, 2016 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takaki/ca57f2b3a42bddaca508c931c26cc6ec to your computer and use it in GitHub Desktop.
Save takaki/ca57f2b3a42bddaca508c931c26cc6ec to your computer and use it in GitHub Desktop.
スマートフォン用のWebページでスリープを防ぐ ref: http://qiita.com/takaki@github/items/f6b0c2cb4aeeaa6aa518
$ npm install --save nosleep.js
import NoSleep from 'nosleep.js/NoSleep'
class App extends Component {
constructor() {
super();
this.noSleep = new NoSleep();
this.state = {sleep: "Sleep"}
}
render() {
return (
<div>
<button onClick={() => {
this.setState({sleep: "No Sleep"});
this.noSleep.enable();
}}>No Sleep
</button>
<button onClick={() => {
this.setState({sleep: "Sleep"});
return this.noSleep.disable();
}}>Sleep
</button>
{this.state.sleep}
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment