Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redux-thunks

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-thunks

Thunk creator for redux

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

redux-thunks

GitHub license Build Status Coverage npm Project Status

Simple thunk creator for redux.

This is meant to smooth over the use of redux-thunk mixed with the use of redux-actions.

Installation

$ yarn add redux-thunks

or

$ npm install --save redux-thunks

Usage

Best used along side redux-actions.

Action definition

import { createAction } from 'redux-actions';
import { createThunk } from 'redux-thunks';

export const setAmount = createAction('SET_AMOUNT');

export const incrementAsync = createThunk('INCREMENT_ASYNC', ({ dispatch, getState }, amount) => {
  doAsyncMath(getState(), amount).then(val => dispatch(setAmount(val)));
});

Use in component/container

dispatch(incrementAsync, 10); // adds 10

API

createThunk

createThunk('name', { dispatch, [getStore] }, [...args])

The syntax is very similar to that of createAction, and it smooths over the differences by similarly exposing a toString method on the thunk creator.

createThunk takes two arguments, a name, and a function to execute when the action is dispatched. The first argument of the function will be an object with dispatch and getState, as provided by redux-thunk. Any additional arguments will be anything specified at the dispatch call site. It's expected that at least one other action will be dispatched from the handler function.

License

MIT © w33ble

FAQs

Package last updated on 31 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc