An open API service indexing awesome lists of open source software.

https://github.com/js2me/react-stonex


https://github.com/js2me/react-stonex

javascript react state-management typescript

Last synced: 2 months ago
JSON representation

Awesome Lists containing this project

README

          

# ReactJS + Stonex
ReactJS integration with Stonex

## How to use
Before at all need to install `react-stonex` (`yarn add react-stonex` or `npm i -S react-stonex`)
This library have dependencies (it should be installed in your project)
```
"react": "^16.4.2",
"react-dom": "^16.4.2",
"stonex": "^0.1.0-alpha"
```

In your React Stonex application:

1. Add `ReactStonexModifier` to your stonex

```
import { StonexStore } from 'stonex'
import { ReactStonexModifier } from 'react-stonex'

const store = new StonexStore(
{
// your modules
},
{
modifiers: [ReactStonexModifier],
}
)
```

2. Add to the root of the React render tree the `Provider` component and send `store` to him props

```
import store from 'path-to-your-store'
import { Provider } from 'react-stonex'

const Root = () => {
return (

// your react tree

)
}
```

3. Attach some components which you need to link with `Stonex` store using the `connect()` function

```
import { connect } from 'react-stonex'

const mapStoreToProps = (state, modules, ownProps) => {

return {
fruit: state.fruits.actualFruit,
createFruit: modules.fruits.createFruit,
// ownProps is not required to return
// because props of your cool component
// already will contains in component's instance
}
}

const WrappedCoolComponent = connect(mapStoreToProps)(YourCoolComponent)

// somewhere in react tree

```

That's all what you need to do to link your Stonex store with React :) Enjoy!