# react-page-model

> The react state management tool for page level

Latest version **1.0.0** (published 2021-03-27) · 0 weekly downloads

## Install

```sh
npm install react-page-model
pnpm add react-page-model
yarn add react-page-model
bun add react-page-model
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2021-03-27 |
| First published | 2021-03-27 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 911.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | kyo4311 |

## Links

- npm: https://www.npmjs.com/package/react-page-model
- npm.io page: https://npm.io/package/react-page-model

## Dependencies (1)

- [react](https://npm.io/package/react.md) ^16.12.0

## Recent versions

- 1.0.0 (latest) — 2021-03-27

## README

# React Page Model

The react state management tool for page level

## Getting Started

Install dependencies,

```bash
$ npm install react-page-model --save
```

**One page, one model**

Create a model that only works on one page,The following table of contents is for reference only.

```
project
└── src
    └── pages
        ├── page1
        │   ├── index.ts
        │   ├── model.ts
        │   ├── part1.ts
        │   ├── part2.ts
        └── page2
            ├── index.ts
            ├── model.ts
            ├── part1.ts
            └── part2.ts
```

**Using react hooksas state management on model.ts**

```ts
import { useState } from "react";

export default function ExampleModel() {
  const [count, setCount] = useState(0);

  return {
    count,
    setCount
  };
}
```

**Inject model**

Using `withPageModel` to inject model into page.

```ts
import React from "react";
import { withPageModel } from "react-page-model";
import model from "./model";

const Example: React.FC<{}> = () => {
  return <div />;
};

export default withPageModel(model)(Example);
```

**Use model**

Any component under the page can use the same status

```ts
import React from "react";
import { usePageModel } from "react-page-model";

const Part1 = () => {
  const { count, setCount } = usePageModel();

  const handChangeCount = () => {
    setCount(count + 1);
  };

  return (
    <div>
      <div>count: {count}</div>
      <button onClick={handChangeCount}>Change count</button>
    </div>
  );
};

export default Part1;
```

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