githubEdit

Other Exports

Other Exports

Redux Toolkit exports some of its internal utilities, and re-exports additional functions from other dependencies as well.

nanoid

An inlined copy of nanoid/nonsecurearrow-up-right. Generates a non-cryptographically-secure random ID string. createAsyncThunk uses this by default for request IDs. May also be useful for other cases as well.

import { nanoid } from '@reduxjs/toolkit'

console.log(nanoid())
// 'dgPXxUz_6fWIQBD8XmiSy'

miniSerializeError

The default error serialization function used by createAsyncThunk, based on https://github.com/sindresorhus/serialize-error. If its argument is an object (such as an Error instance), it returns a plain JS SerializedError object that copies over any of the listed fields. Otherwise, it returns a stringified form of the value: { message: String(value) }.

export interface SerializedError {
  name?: string
  message?: string
  stack?: string
  code?: string
}

export function miniSerializeError(value: any): SerializedError {}

copyWithStructuralSharing

A utility that will recursively merge two similar objects together, preserving existing references if the values appear to be the same. This is used internally to help ensure that re-fetched data keeps using the same references unless the new data has actually changed, to avoid unnecessary re-renders. Otherwise, every re-fetch would likely cause the entire dataset to be replaced and all consuming components to always re-render.

If either of the inputs are not plain JS objects or arrays, the new value is returned.

Exports from Other Libraries

createNextState

The default immutable update function from the immer libraryarrow-up-right, re-exported here as createNextState (also commonly referred to as producearrow-up-right)

current

The current functionarrow-up-right from the immer libraryarrow-up-right, which takes a snapshot of the current state of a draft and finalizes it (but without freezing). Current is a great utility to print the current state during debugging, and the output of current can also be safely leaked outside the producer.

original

The original functionarrow-up-right from the immer libraryarrow-up-right, which returns the original object. This is particularly useful for referential equality check in reducers.

isDraft

The isDraft functionarrow-up-right from the immer libraryarrow-up-right, which checks to see if a given value is a Proxy-wrapped "draft" state.

combineReducers

Redux's combineReducersarrow-up-right, re-exported for convenience. While configureStore calls this internally, you may wish to call it yourself to compose multiple levels of slice reducers.

compose

Redux's composearrow-up-right. It composes functions from right to left. This is a functional programming utility. You might want to use it to apply several store custom enhancers/ functions in a row.

bindActionCreators

Redux's bindActionCreatorsarrow-up-right. It wraps action creators with dispatch() so that they dispatch immediately when called.

createStore

Redux's createStorearrow-up-right. You should not need to use this directly.

applyMiddleware

Redux's applyMiddlewarearrow-up-right. You should not need to use this directly.

Last updated