Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/ziolko/auto-dispatch

The declarative way to fetch data required by your React & Redux app
https://github.com/ziolko/auto-dispatch

Last synced: about 1 month ago
JSON representation

The declarative way to fetch data required by your React & Redux app

Awesome Lists containing this project

README

        

This library exports a React component that automatically dispatches a Redux action
when rendered. You can use it to trigger data fetch instead of doing it imperatively
in `componentDidMount`.

# Example

```js
import { connect } from 'react-redux'
import AutoDispatch from 'auto-dispatch'

// Action creator
const fetchCardDetails = cardId => ({
type: 'FETCH_CARD_DETAILS',
cardId
})

// React component that automatically fetches required data
const Card = props => (



{
/* Card display logic */
}

)
```

# How it works

The action given as an argument is dispatched on initial render and every time
it changes (deep comparison is performed). In the example above action `FETCH_CARD_DETAILS`
is dispatched every time `props.cardId` changes.

# License
https://opensource.org/licenses/MIT