Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/ziolko/auto-dispatch
- Owner: ziolko
- License: mit
- Created: 2018-02-25T17:13:41.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-25T17:34:00.000Z (almost 7 years ago)
- Last Synced: 2024-10-28T13:55:38.195Z (about 2 months ago)
- Language: JavaScript
- Size: 21.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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