1.0.5 • Published 2 years ago

use-before-install-prompt v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

This project has been deprecated. Move to use-pwa-install

use-before-install-prompt

React hook for beforeinstallprompt event

Install

npm i use-before-install-prompt

Usage

import React from 'react';
import useBeforeInstallPrompt from 'use-before-install-prompt';

const App = () => {
  const { isInstalled, addToHomeScreen } = useBeforeInstallPrompt();

  return (
    <>
      {!isInstalled && (
        <button onClick={addToHomeScreen}>Add to home screen</button>
      )}
    </>
  );
};

Options

optionsTypeDescriptionRequiredDefault Value
acceptedFnFunctionCallback function to execute when acceptednoconsole.log()
dismissedFnFunctionCallback function to execute when dismissednoconsole.log()
installedFnFunctionCallback function to execute when installednoconsole.log()

Return value

valueTypeDescription
isInstalledbooleanInstall state
addToHomeScreenFunctionAdd to home screen function

Browser compatibility

https://developer.mozilla.org/en-US/docs/Web/API/BeforeInstallPromptEvent#browser_compatibility