taro-hooks
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

taro hooks logo

V2 | V1


npm package node compatibility build status discord chat vercel


Hooks Library for Taro

✨ Features

  • Fully matched Taro
  • Extending common hooks with ahooks
  • Separate abstraction useRequest
  • Complete type tips
  • Extended h5 missing apis

🚀 Quick Start

# npm
$ npm i taro-hooks
# yarn
$ yarn add taro-hooks
# pnpm
$ pnpm add taro-hooks

We use plugins for extending different frameworks. So you need to install the corresponding plugins according to the framework you are currently using

  • React/PReact/Nerv
# npm
$ npm i @taro-hooks/plugin-react
# yarn
$ yarn add @taro-hooks/plugin-react
# pnpm
$ pnpm add @taro-hooks/plugin-react
// config/index.js
module.exports = {
  // ...
  plugins: ['@taro-hooks/plugin-react'],
  // ...
};
  • Vue3
# npm
$ npm i @taro-hooks/plugin-vue
# yarn
$ yarn add @taro-hooks/plugin-vue
# pnpm
$ pnpm add @taro-hooks/plugin-vue
// config/index.js
module.exports = {
  // ...
  plugins: ['@taro-hooks/plugin-vue'],
  // ...
};

⌨️ Usage

  • React/PReact/Nerv
import { useEnv } from 'taro-hooks';

function Index() {
  const env = useEnv();

  return <View>current env: {env}</View>;
}
  • Vue3
<template>
  <view>current env: {{env}}</view>
</template>

<script setup lang="ts">
  import { useEnv } from 'taro-hooks';

  const env = useEnv();
</script>

🎰 auto-import

We provide the @taro-hooks/plugin-auto-import plugin to help you quickly use the unplugin-auto-import capability.

# npm
$ npm i @taro-hooks/plugin-auto-import
# yarn
$ yarn add @taro-hooks/plugin-auto-import
# pnpm
$ pnpm add @taro-hooks/plugin-auto-import
// config/index.js
const config = {
  // ...
  // The main prerequisite is that you have installed the plugin for the corresponding framework.
  plugins: [
    // If you are using vue3, please install the @taro-hooks/plugin-vue plugin beforehand.
    '@taro-hooks/plugin-vue'
    // If using React/PReact/Nerv, please pre-install the @taro-hooks/plugin-react plugin.
    '@taro-hooks/plugin-react',
    // Finally, the auto-import plugin is configured
    [
      '@taro-hooks/plugin-auto-import',
      {
        // your options, see configuration: https://github.com/antfu/unplugin-auto-import#configuration
      }
    ]
  ],
  // ...
};
  • React/PReact/Nerv
function Index() {
  const env = useEnv();

  return <View>current env: {env}</View>;
}
  • Vue3
<template>
  <view>current env: {{env}}</view>
</template>

<script setup lang="ts">
  const env = useEnv();
</script>

📦 Packages

packages downloads version license
taro-hooks taro-hooks taro-hooks taro-hooks
@taro-hooks/ahooks @taro-hooks/ahooks @taro-hooks/ahooks @taro-hooks/ahooks
@taro-hooks/plugin-vue @taro-hooks/plugin-vue @taro-hooks/plugin-vue @taro-hooks/plugin-vue
@taro-hooks/plugin-react @taro-hooks/plugin-react @taro-hooks/plugin-react @taro-hooks/plugin-react
@taro-hooks/use-request @taro-hooks/use-request @taro-hooks/use-request @taro-hooks/use-request
@taro-hooks/plugin-auto-import @taro-hooks/plugin-auto-import @taro-hooks/plugin-auto-import @taro-hooks/plugin-auto-import

🗨️ Communication

🤸 Contribution

See Contributing Guide.

🍻 Contributors


innocces

💬 📖 👀 📢 🤔 ⚠️ 📦 📋 🎨

ryan

📖 📢 🤔 💻

more contributors

📑 License

MIT.

💰 Sponsoring

📈 Star History

Star History Chart

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.0.0-beta-serro.50canary
2.1.031latest

Version History

VersionDownloads (Last 7 Days)Published
2.1.031
2.0.115
2.0.104
2.0.94
2.0.89
2.0.711
2.0.62
2.0.52
2.0.4108
2.0.30
2.0.20
2.0.10
2.0.00
1.5.1054
2.0.0-beta-serro.50
2.0.0-beta-serro.30
2.0.0-beta-serro.1500
2.0.0-beta-serro.1490
2.0.0-beta-serro.1480
2.0.0-beta-serro.1460
1.5.93
1.5.81
1.5.71
1.5.6149
1.5.51
1.5.414
1.5.35
1.5.21
1.5.11
1.5.022
1.4.86
1.4.72
1.4.61
1.4.50
1.4.42
1.4.33
1.4.21
1.4.10
1.4.00
1.3.20
1.3.10
1.3.00
1.2.00
1.1.13
1.1.00
1.0.24
1.0.12

Package Sidebar

Install

npm i taro-hooks

Weekly Downloads

452

Version

2.1.0

License

MIT

Unpacked Size

324 kB

Total Files

317

Last publish

Collaborators

  • innocces