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

redux-thunk

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-thunk

Thunk middleware for Redux.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is redux-thunk?

Redux Thunk is a middleware for Redux that allows you to write action creators that return a function instead of an action. This can be used to delay the dispatch of an action, or to dispatch only if a certain condition is met. The inner function receives the store methods `dispatch` and `getState` as parameters.

What are redux-thunk's main functionalities?

Asynchronous Actions

This feature allows for asynchronous actions within Redux. The code sample demonstrates how to create an action that fetches data asynchronously and dispatches different actions based on the result of the fetch.

function fetchData() {
  return (dispatch) => {
    dispatch({ type: 'FETCH_DATA_REQUEST' });
    return fetch('https://api.example.com/data')
      .then(response => response.json())
      .then(json => dispatch({ type: 'FETCH_DATA_SUCCESS', payload: json }))
      .catch(error => dispatch({ type: 'FETCH_DATA_FAILURE', error }));
  };
}

Conditional Dispatching

Redux Thunk allows for conditional dispatching of actions based on the current state or any other condition. The code sample shows how to dispatch an action only if certain conditions are met, using the `getState` method to access the current state.

function updateDataIfNeeded(data) {
  return (dispatch, getState) => {
    if (shouldUpdateData(getState(), data)) {
      dispatch({ type: 'UPDATE_DATA', payload: data });
    }
  };
}

Other packages similar to redux-thunk

Keywords

FAQs

Package last updated on 17 Sep 2015

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