# xfi

> A LightWeight JavaScript State Manager

Latest version **0.0.4-dont-use-me2** (published 2022-08-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install xfi
pnpm add xfi
yarn add xfi
bun add xfi
```

## Health

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

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4-dont-use-me2 |
| Published | 2022-08-14 |
| First published | 2021-12-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | lyz |
| Maintainers | lyz_xfy |

## Links

- npm: https://www.npmjs.com/package/xfi
- Repository: https://github.com/CNlyz/stateManager
- Homepage: https://github.com/CNlyz/stateManager#readme
- Issues: https://github.com/CNlyz/stateManager/issues
- npm.io page: https://npm.io/package/xfi

## Recent versions

- 0.0.4-dont-use-me2 (latest) — 2022-08-14
- 0.0.4-dont-use-me — 2022-08-14
- 0.0.4 — 2022-08-14
- 0.0.3-dont.use.me — 2022-08-07
- 0.0.3 — 2022-08-07
- 0.0.2 — 2022-03-06
- 0.0.1 — 2022-01-13
- 0.0.1-alpha.2 — 2021-12-30
- 0.0.1-alpha.1 — 2021-12-30
- 0.0.1-alpha — 2021-12-30

## README

# Introduction

> A LightWeight JavaScript State Manager

### install
```js
npm install xfi
```

### Usage
```js
import { BaseState, getUseStateManager } from 'xfi';

class Person {
    name: string = '';
}

export default class RootState extends BaseState<Person> {
    protected initialState(): Person {
        return new Person();
    }
}

const rootState = new RootState();

export const useStateManager = getUseStateManager(rootState);
```

```js
import React from 'react';
import { useStateManager } from './RootState';

export function PersonInfo(props: { name: string, age: number, height: number }) {
    const { name, dispatch } = useStateManager(root => ({
        name: root.state.name,
        dispatch: root.dispatch
    }));

    const onClickToChangeName = () => {
        dispatch({ name: 'xxx' }); // dispatch a new state
    }

    return (
        <div onClick={onClickToChangeName}>{name}</div>
    );
}
```

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