Coder Social home page Coder Social logo

nick777-pixel / use-stay-awake Goto Github PK

View Code? Open in Web Editor NEW

This project forked from roldanjr/use-stay-awake

0.0 0.0 0.0 1.26 MB

React hook that make device stay awake while actively using your website.

Home Page: https://roldanjr.github.io/use-stay-awake/

License: MIT License

JavaScript 24.65% TypeScript 75.35%

use-stay-awake's Introduction

use-stay-awake

Live Demo

React hook that make device stay awake while actively using your website.

Build Status NPM JavaScript Style Guide License

✨ Features

  • Typescript support
  • Best browser support
  • Easy to implement
  • CPU friendly
  • Zero dependencies

☄️ Installation

  1. Using Yarn

     yarn add --dev use-stay-awake
  2. Using NPM

     npm install --save use-stay-awake

💯 Usage

import React from "react";
import useStayAwake from "use-stay-awake";

function App() {
  const device = useStayAwake();

  return (
    <div>
      <p>
        Status:
        <span>
          {device.canSleep
            ? "Device is allowed to sleep"
            : "Device is not allowed to sleep"}
        </span>
      </p>
      <button
        onClick={() => {
          device.preventSleeping();
        }}
      >
        Prevent Sleeping
      </button>
      <button
        onClick={() => {
          device.allowSleeping();
        }}
      >
        Allow Sleeping
      </button>
    </div>
  );
}

export default App;

🕸️ Properties

Prop Name Type Description
canSleep boolean default: true Indicator if the device allowed to sleep.
preventSleeping function Function that prevent the device from sleeping.
allowSleeping function Function that allow the device from sleeping.

💫 Browser Support

  • Internet Explorer v9-11
  • Microsoft Edge v12-84
  • Firefox v22-81
  • Chrome v4-87
  • Safari v4-14-TP
  • Opera v16-69
  • iOS Safari v3.2-14.0
  • Android Browser v4.4-81
  • Opera Mobile v12-46
  • Chrome for Android v84
  • Firefox for Android v68
  • UC Browser for Android v12.12
  • Samsung Internet v4-12.0
  • QQ Browser v10.4
  • Baidu Browser v7.12
  • KaiOS Browser v2.5

🛠 Development

Thank you so much for contributing! 💙

⚡ Quick Setup

  1. Clone the repository

     git clone https://github.com/roldanjr/use-stay-awake
  2. Locate library folder

     cd use-stay-awake
  3. Install library dependencies

     yarn install or npm install
  4. Locate demo folder and install dependencies

     cd demo
     yarn install or npm install
  5. Start development server under root folder

     yarn develop or npm run develop

📑 License

MIT © Roldan Montilla Jr

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.