innocces / taro-hooks

Hooks Library for Taro
https://next-taro-hooks.pages.dev
MIT License
430 stars 36 forks source link
api composition-api-vue3 es hooks javascript lib library miniprogram monorepo pnpm pnpm-workspaces react react-native rn taro typescript vue web webpack wechat

taro hooks logo

V2 | V1


npm package node compatibility build status discord chat vercel


Hooks Library for Taro

✨ Features

🚀 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

# 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'],
  // ...
};
# 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

import { useEnv } from 'taro-hooks';

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

  return <View>current env: {env}</View>;
}
<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
      }
    ]
  ],
  // ...
};
function Index() {
  const env = useEnv();

  return <View>current env: {env}</View>;
}
<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