# redux-thunk-loadings

> A loading wrapper for redux-thunk

Latest version **0.0.3** (published 2019-04-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install redux-thunk-loadings
pnpm add redux-thunk-loadings
yarn add redux-thunk-loadings
bun add redux-thunk-loadings
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2019-04-19 |
| First published | 2019-04-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Jarvan Yeung |
| Maintainers | jarvanycb |
| Keywords | redux, redux-thunk, loading, loadings, redux-thunk-loadings |

## Links

- npm: https://www.npmjs.com/package/redux-thunk-loadings
- Repository: https://github.com/georgebbbb/redux-thunk-loadings
- Homepage: https://github.com/georgebbbb/redux-thunk-loadings#readme
- Issues: https://github.com/georgebbbb/redux-thunk-loadings/issues
- npm.io page: https://npm.io/package/redux-thunk-loadings

## Dependencies (1)

- [is-promise](https://npm.io/package/is-promise.md) ^2.1.0

## Recent versions

- 0.0.3 (latest) — 2019-04-19
- 0.0.2 — 2019-04-10
- 0.0.1 — 2019-04-09

## README

# Redux Thunk Loadings
A loading wrapper for redux-thunk 

## Installation
```js
npm install redux-thunk-loadings
```

```js
import { createStore, combineReducers, applyMiddleware } from 'redux'
import { loadingsReducer } from 'redux-thunk-loadings'
import thunk from 'redux-thunk' 
 
const store = createStore(
  combineReducers({
    loadings: loadingsReducer
  }), 
  applyMiddleware(thunk)
)
```

## Motivation
In most cases, loading is necessary when we request API. redux-thunk-loadings is a way to reduce boilerplate

#### Before
```js
export const setListPostsLoading = (isLoading) => ({
  type: 'SET_LIST_POSTS_LOADING',
  isLoading
})

export const listPosts = (dispatch) => {
  dispatch(setListPostsLoading(true))
  return listPosts().then(
    () => dispatch(setListPostsLoading(false))
  )
}
```
#### After
```js
export const listPosts = () => loadings('listPosts', () => {
  return listPosts()
})
```

#### Finally

```js
  @connect(
    ({ loadings }) => ({
      loadings
    })
  )
  Class PostList extends Component {
    render() {
      const { loadings } = this.props
      return (
        loadings.listPosts ? <Loading /> : null
      )
    }
  }
```

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