# @cherry-tomato/react

> [![npm version](https://img.shields.io/npm/v/@cherry-tomato/react.svg?maxAge=3600)](https://www.npmjs.org/package/@cherry-tomato/react)

Latest version **3.1.3** (published 2024-07-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @cherry-tomato/react
pnpm add @cherry-tomato/react
yarn add @cherry-tomato/react
bun add @cherry-tomato/react
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.1.3 |
| Published | 2024-07-15 |
| First published | 2019-11-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 15.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | huey.LS |
| Maintainers | ignous |

## Links

- npm: https://www.npmjs.com/package/@cherry-tomato/react
- Repository: https://github.com/huey-LS/cherry-tomato
- Homepage: https://github.com/huey-LS/cherry-tomato#readme
- Issues: https://github.com/huey-LS/cherry-tomato/issues
- npm.io page: https://npm.io/package/@cherry-tomato/react

## Dependencies (1)

- [@cherry-tomato/core](https://npm.io/package/@cherry-tomato/core.md) ^3.1.1

## Recent versions

- 3.1.3 (latest) — 2024-07-15
- 3.0.0-beta.3 (beta) — 2023-09-06
- 3.1.2 — 2024-07-12
- 3.1.1 — 2024-07-08
- 3.1.0 — 2024-05-31
- 3.0.0 — 2023-09-22
- 3.0.0-beta.2 — 2023-09-06
- 3.0.0-beta.1 — 2023-09-06
- 3.0.0-beta.0 — 2023-03-31
- 2.1.1 — 2022-07-04
- 2.1.0 — 2022-05-18
- 2.0.7 — 2020-12-22
- 2.0.6 — 2020-11-11
- 2.0.5 — 2020-11-11
- 2.0.4 — 2020-11-11
- … 12 more at https://npm.io/package/@cherry-tomato/react/versions

## README

# @cherry-tomato/react
[![npm version](https://img.shields.io/npm/v/@cherry-tomato/react.svg?maxAge=3600)](https://www.npmjs.org/package/@cherry-tomato/react)

# 介绍
`cherry-tomato` 配合 `react` 使用的工具，使页面自动更新的框架

# 安装
```
npm install --save @cherry-tomato/react
```

# API 目录
- [API](#api)
  - [observer](#observer) 监听组件 Props
  - [observe](#observe) 监听组件属性


## API 介绍
### observer 监听组件 Props

绑定方法1: 作为 `Component` 类的装饰其，会自监听`Props`中传入的 `Model` 并响应更新
```js
  import { Model } from '@cherry-tomato/core';
  import { observer } from '@cherry-tomato/react';

  class Item extend Model {
    ...
  }

  @observer()
  class CustomComponent extends React.Component {
    render () {
      const item = this.props.item;
      return (
        <div>{item.title}</div>
      )
    }
  }

  (
    <CustomComponent item={new Item()} />
  )
```

### observe 监听组件属性

绑定方法2: 作为 `Component` 属性的装饰其，会自监听`item`并响应更新
```js
  import { Model } from '@cherry-tomato/core';
  import { observer } from '@cherry-tomato/react';

  class Item extend Model {
    ...
  }

  class CustomComponent extends React.Component {
    @observe
    item = new Item();

    render () {
      const item = this.item;
      return (
        <div>{item.title}</div>
      )
    }
  }
```

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