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

@reduxjs/toolkit

Package Overview
Dependencies
Maintainers
6
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@reduxjs/toolkit

The official, opinionated, batteries-included toolset for efficient Redux development

  • 2.5.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
6
Created

What is @reduxjs/toolkit?

The @reduxjs/toolkit package is a toolset for efficient Redux development. It is intended to be the standard way to write Redux logic, providing utilities to simplify common tasks such as store setup, creating reducers and actions, and writing immutable update logic.

What are @reduxjs/toolkit's main functionalities?

Creating a Redux Store

This feature simplifies the setup of the Redux store with sensible defaults and middleware like Redux Thunk.

import { configureStore } from '@reduxjs/toolkit';

const store = configureStore({ reducer: rootReducer });

Creating Slices

Slices are a way to define reducers and associated actions together in a single, concise object.

import { createSlice } from '@reduxjs/toolkit';

const counterSlice = createSlice({
  name: 'counter',
  initialState: 0,
  reducers: {
    increment: state => state + 1,
    decrement: state => state - 1
  }
});

export const { increment, decrement } = counterSlice.actions;

Creating Async Thunks

Async thunks are used to handle asynchronous logic in Redux. They can be dispatched like regular actions and handle the lifecycle of an async request.

import { createAsyncThunk } from '@reduxjs/toolkit';

const fetchUserById = createAsyncThunk(
  'users/fetchByIdStatus',
  async (userId, thunkAPI) => {
    const response = await fetch(`https://api.example.com/users/${userId}`);
    return await response.json();
  }
);

Immutable Update Logic

The toolkit enables writing reducers with simpler immutable update logic using the Immer library under the hood.

import { createReducer } from '@reduxjs/toolkit';

const counterReducer = createReducer(0, {
  increment: state => state + 1,
  decrement: state => state - 1
});

Other packages similar to @reduxjs/toolkit

Keywords

FAQs

Package last updated on 11 Dec 2024

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