Other Exports
Redux Toolkit exports some of its internal utilities, and re-exports additional functions from other dependencies as well.
nanoid
nanoidAn inlined copy of nanoid/nonsecure. Generates a non-cryptographically-secure random ID string. Automatically used by createAsyncThunk for request IDs, but may also be useful for other cases as well.
import { nanoid } from '@reduxjs/toolkit'
console.log(nanoid())
// 'dgPXxUz_6fWIQBD8XmiSy'Exports from Other Libraries
createNextState
createNextStateThe default immutable update function from the immer library, re-exported here as createNextState (also commonly referred to as produce)
current
currentThe current function from the immer library, 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
originalThe original function from the immer library, which returns the original object. This is particularly useful for referential equality check in reducers.
import { createReducer, createAction, current } from '@reduxjs/toolkit'
interface Todo {
//...
}
const addTodo = createAction<Todo>('addTodo')
const initialState: Todo[] = []
const todosReducer = createReducer(initialState, builder => {
builder.addCase(addTodo, (state, action) => {
state.push(action.payload)
console.log(current(state))
})
})combineReducers
combineReducersRedux's combineReducers, re-exported for convenience. While configureStore calls this internally, you may wish to call it yourself to compose multiple levels of slice reducers.
compose
composeRedux's compose. 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
bindActionCreatorsRedux's bindActionCreators. It wraps action creators with dispatch() so that they dispatch immediately when called.
createStore
createStoreRedux's createStore. You should not need to use this directly.
applyMiddleware
applyMiddlewareRedux's applyMiddleware. You should not need to use this directly.
Last updated
Was this helpful?