# reconstate

> React store built on top of the new context API

Latest version **1.0.4** (published 2019-02-20) · ISC license · 0 weekly downloads

## Install

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

## 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.4 |
| Published | 2019-02-20 |
| First published | 2019-02-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 6.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | vinpro |
| Maintainers | vinpro |

## Links

- npm: https://www.npmjs.com/package/reconstate
- Homepage: https://github.com/vinpro24/reconstate#readme
- Issues: https://github.com/vinpro24/reconstate/issues
- npm.io page: https://npm.io/package/reconstate

## Dependencies (2)

- [react-is](https://npm.io/package/react-is.md) ^16.7.0
- [hoist-non-react-statics](https://npm.io/package/hoist-non-react-statics.md) ^3.2.1

## Recent versions

- 1.0.4 (latest) — 2019-02-20
- 1.0.3 — 2019-02-18
- 1.0.2 — 2019-02-17
- 1.0.1 — 2019-02-15
- 1.0.0 — 2019-02-15

## README

## Reconstate
Eeasy state management and tracking of Provider/Subscribe/connect/dispatch relationships when using React's Context API

# Demo
[Check Demo](https://snack.expo.io/@vinpro/reconstate-demo)


```
npm install reconstate
```

# App.js

```js
import { Provider } from 'reconstate';
const initState = {
    count: 1
}

const config = {
    persist: {
        storage: AsyncStorage // localStorage with web
    }
}

class App extends React.Component {
    render() {
        return (
            <Provider value={initState} config={config}>
                <YourAppComponent>
            </Provider>
        )
    }
}
```

# Connect

```js
import { connect } from 'reconstate'

class Counter extends React.PureComponent {
    render() {
        const { count, dispatch } = this.props
        return (
            <View style={{ flex: 1 }}>
                <Text>{count}</Text>
                <Button
                    onPress={() => dispatch(state => ({ count: state.count + 1 }))} title="+"
                />
            </View>
        )
    }
}

const mapStateToProps = (state, props) => ({
    count: state.count
})

export default connect(mapStateToProps)(Counter)
```

# Subscribe

```js
import { Subscribe } from 'reconstate'

class Subscriber extends React.PureComponent {
    render() {
        return (
            <View style={{ flex: 1 }}>
                <Subscribe>
                    {({ count }) => {
                        return <Text>{count}</Text>
                    }}
                </Subscribe>
            </View>
        )
    }
}
```

## getContext

```js
import { getContext } from 'reconstate'


getContext(state => {
    // return global state
})
getContext().then(state => {
    // return global state
})
```

## Dispatch

```js
import { dispatch } from 'reconstate'

const count = value => {
    dispatch((state) => ({ count: state.count + value }))
}
```

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