# @wakeapp/taro-components-react

> 惟客宝 Taro React 组件库，基于 @tarojs/components，主要用于解决兼容性问题

Latest version **1.0.17** (published 2025-03-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @wakeapp/taro-components-react
pnpm add @wakeapp/taro-components-react
yarn add @wakeapp/taro-components-react
bun add @wakeapp/taro-components-react
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: esm support; no vulnerabilities; high maintenance score; popular repo.

Warnings: low downloads; no types.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 1.0.17 |
| Published | 2025-03-27 |
| First published | 2022-03-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 601.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 37762 |
| Maintainers | carney520, wkfe |

## Links

- npm: https://www.npmjs.com/package/@wakeapp/taro-components-react
- Repository: https://github.com/NervJS/taro
- Homepage: https://github.com/NervJS/taro#readme
- Issues: https://github.com/NervJS/taro/issues
- npm.io page: https://npm.io/package/@wakeapp/taro-components-react

## Dependencies (5)

- [swiper](https://npm.io/package/swiper.md) ^6.8.4
- [lru-cache](https://npm.io/package/lru-cache.md) ^6.0.0
- [shallowequal](https://npm.io/package/shallowequal.md) ^1.1.0
- [@wakeapp/i18n](https://npm.io/package/@wakeapp/i18n.md) ^1.0.17
- [resolve-pathname](https://npm.io/package/resolve-pathname.md) ^3.0.0

## Recent versions

- 1.0.17 (latest) — 2025-03-27
- 1.0.16 — 2023-11-29
- 1.0.15 — 2023-11-15
- 1.0.14 — 2023-11-01
- 1.0.13 — 2023-08-30
- 1.0.12 — 2023-06-14
- 1.0.11 — 2023-05-17
- 1.0.10 — 2023-04-26
- 1.0.9 — 2023-04-12
- 1.0.7 — 2023-03-08
- 1.0.6 — 2023-03-01
- 1.0.5 — 2023-02-08
- 1.0.4 — 2023-01-18
- 1.0.3 — 2023-01-11
- 1.0.2 — 2022-12-11
- … 4 more at https://npm.io/package/@wakeapp/taro-components-react/versions

## README

# @wakeda/taro-components-react

Taro 组件库（React 版本）。

`@tarojs/components` 使用了基于 `Web Components` 的 **Stencil** 框架进行开发，于部分手机会出现兼容性问题：

- 多行文字截断失效
- 部分安卓机（OV 居多），样式 `visibility` 切换失败导致页面白屏

因此开发者可以使用此包对 **React** 框架的 H5 组件库进行替代，来提高兼容性。

## 使用方法

#### 1. 设置项目配置 `h5.useHtmlComponents`

```js
// config/index.js
module.exports = {
  h5: {
    // 注意：暂时关闭，等所有组件迁移过来之后开启
    useHtmlComponents: true,
    // 设置 alias
    webpackChain(config) {
      config.resolve.alias.set(
        '@tarojs/components$',
        '@wakeda/taro-components-react/index'
      );
      console.log(config.resolve.alias);
    },
  },
};
```

## 改造方法

目前只适配了 `View`、`Text`、`Swiper` 组件，开发者可以根据使用到的组件按以下改造方法进行适配：

### 拷贝 Taro v2 的对应组件，进行修改

从[这里](https://github.com/NervJS/taro/tree/2.x/packages/taro-components/src/components)拷贝 Taro2 的对应组件到 `taro/packages/taro-components-react/src/components` 目录下。

组件需要修改的地方有：

1. 把 `Nerv` 相关的引用修改为 `react`
2. 文件改为 `.tsx`，增加 Typings（可选）

### 修改引用入口、rollup 配置

在入口文件增加组件的导出：

```js
// taro-components/react/index
export { xxxx } from './dist/xxx';
```

修改 rollup 配置，添加 input：

```js
// taro-components/rollup.config.js
export default {
  input: {
    'xxx/index': 'src/components/xxx/index.[jsx|tsx]',
  },
};
```

### 编译组件库

```shell
cd taro/packages/taro-components-react
npm run dev
# 完成后重新刷新浏览器即可
```

---
_Source: https://npm.io/package/@wakeapp/taro-components-react · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
