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

https://github.com/kanitsharma/react-deflux

Flux architecture implemented using react's new context API
https://github.com/kanitsharma/react-deflux

flux flux-architecture react react16

Last synced: 21 days ago
JSON representation

Flux architecture implemented using react's new context API

Awesome Lists containing this project

README

        

# React Deflux

Yet another flux implementation, with bindings for react.
Built over react's new context API.

## Getting Started

```javascript
npm install --save react-deflux
```

Wrap ReState over your root component.

```javascript

import Provider from 'react-deflux';

```

That's it, now any child component can connect to store.

```javascript

import { connect } from 'react-deflux';

const App = ({ buttonClick }) => (


Fire Action!

);

const mapStateToProps = state => ({
...state
})

const mapDispatchToProps = (dispatch) => ({
buttonClick: _ => dispatch({ type: 'DUMMY_ACTION'})
})

export default connect(mapStateToProps, mapDispatchToProps)(App)

```

## Middleware

This the best part. You can pass any function (middleware) to the applyMiddleWare prop, and it will be fired with every action.

```javascript

// Handling async with middleware

export default state => action => dispatch => (
action.type === 'FETCH_DATA' &&
fetch('https://jsonplaceholder.typicode.com/posts/1')
.then(response => response.json())
.then(json => dispatch({ type: 'FETCHED_DATA', payload: { apiData: json } }))
)

```