# react-global-shared

> react全局状态管理,更自由,更简单.

Latest version **1.0.3** (published 2019-08-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-global-shared
pnpm add react-global-shared
yarn add react-global-shared
bun add react-global-shared
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2019-08-21 |
| First published | 2019-08-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 11 |
| Unpacked size | 3.8 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | fuxuewei |

## Links

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

## Dependencies (11)

- [react](https://npm.io/package/react.md) ^16.8.6
- [enzyme](https://npm.io/package/enzyme.md) ^3.10.0
- [react-dom](https://npm.io/package/react-dom.md) ^16.8.6
- [@types/jest](https://npm.io/package/@types/jest.md) 24.0.13
- [@types/node](https://npm.io/package/@types/node.md) ^12.0.10
- [@types/react](https://npm.io/package/@types/react.md) ^16.9.2
- [@types/react-dom](https://npm.io/package/@types/react-dom.md) ^16.9.0
- [react-router-dom](https://npm.io/package/react-router-dom.md) ^5.0.1
- [immutability-helper](https://npm.io/package/immutability-helper.md) ^3.0.0
- [@types/react-router-dom](https://npm.io/package/@types/react-router-dom.md) ^4.3.3
- [enzyme-adapter-react-16](https://npm.io/package/enzyme-adapter-react-16.md) ^1.14.0

## Recent versions

- 1.0.3 (latest) — 2019-08-21
- 1.0.2 — 2019-08-21
- 1.0.1 — 2019-08-21
- 0.0.1 — 2019-08-21
- 1.0.0 — 2019-08-20

## README

## react-global-shared

react全局状态管理,更自由,更简单.

[![MIT](https://img.shields.io/dub/l/vibe-d.svg?style=flat-square)](http://opensource.org/licenses/MIT)
![Travis (.org)](https://travis-ci.org/meihuanyu/react-global-shared.svg?branch=master)

## ✨ Features

- 全局状态管理,兼容hooks
- 可以再非组件中操作状全局状态

## 简介
修改objectState中state,调用的地方会重新render
hooks: useGlobalState
普通组件: connect
```
// 直接返回state
useGlobalState(objeact: objectState): state

//  注入state到Component
connect(Component: React.ComponentType, ...objectState):React.ComponentType

```

objectState

* name 必填值 用于注入普通组件中
* state 必填值 用于初始化值
* [key as string]: () => 在方法中直接修改state值即可
### Installing

```
yarn add react-global-shared
```

## Running the tests
```
yarn run test
```
## Usage
olny tow api
```
import { connect, useGlobalState } from 'react-global-shared
```

## Quick Start

state
```
// userState.js
export const userState = {
    name: "user",
    state: { email: "init@exapmle.com" },
    changeEmail: function(){
        this.state = { email: "hh@exapmle.com"}
    }
}
```

commonly exapmle
```
// App.js
import React from 'react'
import { connect } from 'react-global-shared
import { userState } from './userState'
class App extends React.Component{
    render(){
        const user = this.props.user
        return <div>
                    <span>{user.email}</span>
                    <button onClick={userState.changeEmail}> change email</button>
                </div>
    }
}
export default connect(App, userState)

```

hooks exapmle
```
// App.js
import React from 'react'
import { useGlobalState } from 'react-global-shared'
import { userState } from './userState'

export default () => {
    const user = useGlobalState(userState)
    return <div>
                <span>{user.email}</span>
                <button onClick={userState.changeEmail}> change email</button>
            </div>
}
```

// 任意function 可直接调用
```
// util.js
import { userState } from './userState'
const change = (email) => {
    userState.changeEmail(email)
    return email
}

```

## FAQ

* 修改了state,没有render？

## Built With

* [immutability-helper](https://github.com/kolodny/immutability-helper) - Mutate a copy of data without changing the original source


## Contributing

Please read [CONTRIBUTING.md](https://gist.github.com/PurpleBooth/b24679402957c63ec426) for details on our code of conduct, and the process for submitting pull requests to us.



## License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

## Acknowledgments

* girl friend give strong backing

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