@dotmind/react-use-pwa

中文文档
1.0.4发布于 2021/04/23MITTypeScriptCommonJS零依赖近 30 天下载 5035

Prompt to install Progressive Web App and more with React hooks

原始使用文档
文档目录8 节
  1. Menu
  2. ✋ Disclaimer
  3. 💻 Installation
  4. 👷‍♂️ How it's work
  5. usePwa usage
  6. usePwaAppSize usage
  7. ⚡️ Contributing
  8. 🔐 License
header

@dotmind/react-use-pwa

Prompt to install Progressive Web App and more with React hooks. Builded by .mind.io

Menu

✋ Disclaimer

This package help to prompt to install and manage Progressive Web App (PWA) installed with React hooks.

Please check if your app have the required criteria before use : web.dev/install-criteria

Want to make a good PWA ? Read this

SSR support ✅

💻 Installation

yarn add @dotmind/react-use-pwa

or

npm i @dotmind/react-use-pwa --save

👷‍♂️ How it's work

usePwa usage

import { useEffect, useCallback  } from 'react';
import { usePwa } from '@dotmind/react-use-pwa';

const App = () => {
  const {
    installPrompt,
    isInstalled,
    isStandalone,
    isOffline,
    canInstall,
  } = usePwa();

  const handleInstallPrompt = useCallback(() => {
    if (canInstall) {
      installPrompt();
    }
  }, [canInstall, installPrompt]);

  if (isOffline) {
    return <p>Please check your network 📶</p>;
  }

  if (!isInstalled || !isStandalone) {
    return (
      <button onClick={handleInstallPrompt}>
        <span>Hey install our app 👋</span>
      </button>
    );
  }

  return (
    <h1>Welcome to our new app 🚀</h1>
  );
};

descriptiontype
installPromptShow install prompt() => Promise<void>
isInstalledIs app installed on deviceboolean
isStandaloneIs app run in standalone modeboolean
isOfflineIs app run in offline modeboolean
canInstallDevice can install appboolean
userChoicePrompt user choice'accepted' | 'dismissed' | 'unknow'

usePwaAppSize usage

Choose app launching width and height (only in desktop standalone mode).

import { usePwaAppSize } from '@dotmind/react-use-pwa';

const App = () => {
  usePwaAppSize(400, 560);

  return <AppProvider />;
};
argumentsdescriptionrequireddefault value
widthApp widthfalse800
heightApp heightfalse800
optionsApp optionsfalse{ fixed: false }

App options

optiondescriptiontype
fixedUser can't resize app width & heightboolean

⚡️ Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

🔐 License

MIT

版本与发布记录

@dotmind/react-use-pwa 共发布 5 个版本,首次发布于 2021/04/21;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.4latest2021/04/235 年前
1.0.32021/04/235 年前
1.0.22021/04/235 年前
1.0.12021/04/235 年前
1.0.02021/04/215 年前

关于 @dotmind/react-use-pwa 的常见问题

@dotmind/react-use-pwa 是什么?

Prompt to install Progressive Web App and more with React hooks

如何安装 @dotmind/react-use-pwa?

在项目目录运行 npm install @dotmind/react-use-pwa,或使用 pnpm add / yarn add / bun add。

@dotmind/react-use-pwa 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dotmind/react-use-pwa 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@dotmind/react-use-pwa 可以商用吗?

@dotmind/react-use-pwa 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dotmind/react-use-pwa 的下载量有多少?

根据 npm 官方下载统计,@dotmind/react-use-pwa 在 2026/10/13 – 2026/11/11 这 30 天内被下载 5,035 次,日均约 168 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dotmind/react-use-pwa 还在维护吗?

最新版本 1.0.4 发布于 2021/04/23(5 年前);至今共发布 5 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/04/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。