Type of reducer.
Infer action union type from a ReducersMapObject
.
Object map of reducers as provided to combineReducers(map: M)
.
Defines a mapping from action types to corresponding action object shapes.
A type describing the return value of createAsyncThunk
.
Might be useful for wrapping createAsyncThunk
in custom abstractions.
A ThunkAction created by createAsyncThunk
.
Dispatching it returns a Promise for either a
fulfilled or rejected action.
Also, the returned value contains an abort()
method
that allows the asyncAction to be cancelled from the outside.
Options object for createAsyncThunk
.
A type describing the payloadCreator
argument to createAsyncThunk
.
Might be useful for wrapping createAsyncThunk
in custom abstractions.
A type describing the return value of the payloadCreator
argument to createAsyncThunk
.
Might be useful for wrapping createAsyncThunk
in custom abstractions.
An case reducer is a reducer function for a specific action type. Case
reducers can be composed to full reducers using createReducer()
.
Unlike a normal Redux reducer, a case reducer is never called with an
undefined
state to determine the initial state. Instead, the initial
state is explicitly specified as an argument to createReducer()
.
In addition, a case reducer can choose to mutate the passed-in state
value directly instead of returning a new state. This does not actually
cause the store state to be mutated directly; instead, thanks to
immer, the mutations are
translated to copy operations that result in a new state.
Derives the slice's actions
property from the reducers
options
A CaseReducer with a prepare
method.
A mapping from action types to case reducers for createReducer()
.
Callback function type, to be used in ConfigureStoreOptions.enhancers
create loadable slice without API config
create loadable slice with API config
A minimal observable of state changes. For more information, see the observable proposal: https://github.com/tc39/proposal-observable
The minimal observable subscription method.
Any object that can be used as an observer.
The observer object should have a next
method.
An object with an unsubscribe
method that can
be used to unsubscribe the observable from the store, and prevent further
emission of values from the observable.
An Observer is used to receive data from an Observable, and is supplied as an argument to subscribe.
A generated selector that is assumed to have one additional argument
Represents the actual selectors generated by createSelector
.
The selector is:
A selector that is assumed to have one additional argument, such as the props from a React component
An action with a string type and an associated payload. This is the
type of action returned by createAction()
action creators.
The type of the action's payload.
the type used for the action type.
The type of the action's meta (optional)
The type of the action's error (optional)
An action creator that produces actions with a payload
attribute.
the payload
type
the type
of the resulting action
if the resulting action is preprocessed by a prepare
method, the signature of said method.
Recursively makes combined state objects partial. Only combined state root objects (i.e. the generated higher level object with keys mapping to individual reducers) are partial.
A "prepare" method to be used as the second parameter of createAction
.
Takes any number of arguments and returns a Flux Standard Action without
type (will be added later) that must contain a payload (might be undefined).
The type of state consumed and produced by this reducer.
The type of actions the reducer can potentially respond to.
A reducer (also called a reducing function) is a function that accepts an accumulation and a value and returns a new accumulation. They are used to reduce a collection of values down to a single value
Reducers are not unique to Redux—they are a fundamental concept in
functional programming. Even most non-functional languages, like
JavaScript, have a built-in API for reducing. In JavaScript, it's
Array.prototype.reduce()
.
In Redux, the accumulated value is the state object, and the values being accumulated are actions. Reducers calculate a new state given the previous state and an action. They must be pure functions—functions that return the exact same output for given inputs. They should also be free of side-effects. This is what enables exciting features like hot reloading and time travel.
Reducers are the most important concept in Redux.
Do not put API calls into reducers.
Infer reducer union type from a ReducersMapObject
.
Object map of reducers as provided to combineReducers(map: M)
.
Object whose values correspond to different reducer functions.
The type of actions the reducers can potentially respond to.
An action creator attached to a slice.
The type describing a slice's reducers
option.
Infer a combined state shape from a ReducersMapObject
.
Object map of reducers as provided to combineReducers(map: M)
.
Store extension that is mixed into the Store type.
State extension that is mixed into the state type.
A store enhancer is a higher-order function that composes a store creator to return a new, enhanced store creator. This is similar to middleware in that it allows you to alter the store interface in a composable way.
Store enhancers are much the same concept as higher-order components in React, which are also occasionally called “component enhancers”.
Because a store is not an instance, but rather a plain-object collection of
functions, copies can be easily created and modified without mutating the
original store. There is an example in compose
documentation
demonstrating that.
Most likely you'll never write a store enhancer, but you may use the one provided by the developer tools. It is what makes time travel possible without the app being aware it is happening. Amusingly, the Redux middleware implementation is itself a store enhancer.
The return type of the thunk's inner function
The redux state
Optional extra argument passed to the inner function (if specified when setting up the Thunk middleware)
The (non-thunk) actions that can be dispatched.
A "thunk" action (a callback function that can be dispatched to the Redux store.)
Also known as the "thunk inner function", when used with the typical pattern of an action creator function that returns a thunk action.
A hook to access the redux store's state. This hook takes a selector function as an argument. The selector is called with the store state.
This hook takes an optional equality comparison function as the second parameter that allows you to customize the way the selected state is compared to determine whether the component needs to be re-rendered.
the selector function
the function that will be used to determine equality
the selected state
A hook to access the redux store's state. This hook takes a selectors and combiner function as an arguments. The selector will be created by passing selectors and combiner to combineSelectors.
Used on a SliceCaseReducers object.
Ensures that if a CaseReducer is a CaseReducerWithPrepare
, that
the reducer
and the prepare
function use the same type of payload
.
Might do additional such checks in the future.
This type is only ever useful if you want to write your own wrapper around
createSlice
. Please don't use it otherwise!
create a component wrapper that calls buildCallbacks
create a component wrapper that calls buildCallbacks
create a component wrapper that calls buildCallbacks
create a component wrapper that calls buildCallbacks
create a component wrapper that calls buildCallbacks
create a component wrapper that calls buildCallbacks
Internal "virtual" symbol used to make the CombinedState
type unique.
Creates a store enhancer that applies middleware to the dispatch method of the Redux store. This is handy for a variety of tasks, such as expressing asynchronous actions in a concise manner, or logging every action payload.
See redux-thunk
package as an example of the Redux middleware.
Because middleware is potentially asynchronous, this should be the first store enhancer in the composition chain.
Note that each middleware will be given the dispatch
and getState
functions as named arguments.
A store enhancer applying the middleware.
Turns an object whose values are action creators, into an object with the
same keys, but with every function wrapped into a dispatch
call so they
may be invoked directly. This is just a convenience method, as you can call
store.dispatch(MyActionCreators.doSomething())
yourself just fine.
For convenience, you can also pass a single function as the first argument, and get a function in return.
An object whose values are action creator functions.
One handy way to obtain it is to use ES6 import * as
syntax. You may
also pass a single function.
The dispatch
function available on your Redux store.
The object mimicking the original object, but with every action
creator wrapped into the dispatch
call. If you passed a function as
actionCreator
, the return value will also be a single function.
Turns an object whose values are different reducer functions, into a single reducer function. It will call every child reducer, and gather their results into a single state object, whose keys correspond to the keys of the passed reducer functions.
Combined state object type.
An object whose values correspond to different reducer
functions that need to be combined into one. One handy way to obtain it
is to use ES6 import * as reducers
syntax. The reducers may never
return undefined for any action. Instead, they should return their
initial state if the state passed to them was undefined, and the current
state for any unrecognized action.
A reducer function that invokes every reducer inside the passed object, and builds a state object with the same shape.
combine multiple selectors/slice selectors into one selector
Composes single-argument functions from right to left. The rightmost function can take multiple arguments as it provides the signature for the resulting composite function.
R function obtained by composing the argument functions from right
to left. For example, compose(f, g, h)
is identical to doing
(...args) => f(g(h(...args)))
.
Composes single-argument functions from right to left. The rightmost function can take multiple arguments as it provides the signature for the resulting composite function.
R function obtained by composing the argument functions from right
to left. For example, compose(f, g, h)
is identical to doing
(...args) => f(g(h(...args)))
.
A utility function to create an action creator for the given action type string. The action creator accepts a single argument, which will be included in the action object as a field called payload. The action creator function will also have its toString() overriden so that it returns the action type, allowing it to be used in reducer logic that is looking for that action type.
The action type to use for created actions.
A utility function to create an action creator for the given action type string. The action creator accepts a single argument, which will be included in the action object as a field called payload. The action creator function will also have its toString() overriden so that it returns the action type, allowing it to be used in reducer logic that is looking for that action type.
The action type to use for created actions.
"Draft-Safe" version of reselect
's createSelector
:
If an immer
-drafted object is passed into the resulting selector's first argument,
the selector will act on the current draft value, instead of returning a cached value
that might be possibly outdated if the draft has been modified since.
"Draft-Safe" version of reselect
's createSelector
:
If an immer
-drafted object is passed into the resulting selector's first argument,
the selector will act on the current draft value, instead of returning a cached value
that might be possibly outdated if the draft has been modified since.
"Draft-Safe" version of reselect
's createSelector
:
If an immer
-drafted object is passed into the resulting selector's first argument,
the selector will act on the current draft value, instead of returning a cached value
that might be possibly outdated if the draft has been modified since.
Creates a middleware that checks whether any state was mutated in between dispatches or during a dispatch. If any mutations are detected, an error is thrown.
Middleware options.
The produce
function takes a value and a "recipe function" (whose
return value often depends on the base state). The recipe function is
free to mutate its first argument however it wants. All mutations are
only ever applied to a copy of the base state.
Pass only a function to create a "curried producer" which relieves you from passing the recipe function every time.
Only plain objects and arrays are made mutable. All other objects are considered uncopyable.
Note: This function is bound to its Immer
instance.
a new state, or the initial state if nothing was modified
The produce
function takes a value and a "recipe function" (whose
return value often depends on the base state). The recipe function is
free to mutate its first argument however it wants. All mutations are
only ever applied to a copy of the base state.
Pass only a function to create a "curried producer" which relieves you from passing the recipe function every time.
Only plain objects and arrays are made mutable. All other objects are considered uncopyable.
Note: This function is bound to its Immer
instance.
a new state, or the initial state if nothing was modified
The produce
function takes a value and a "recipe function" (whose
return value often depends on the base state). The recipe function is
free to mutate its first argument however it wants. All mutations are
only ever applied to a copy of the base state.
Pass only a function to create a "curried producer" which relieves you from passing the recipe function every time.
Only plain objects and arrays are made mutable. All other objects are considered uncopyable.
Note: This function is bound to its Immer
instance.
a new state, or the initial state if nothing was modified
Curried producer that infers curried from the State generic, which is explicitly passed in.
The produce
function takes a value and a "recipe function" (whose
return value often depends on the base state). The recipe function is
free to mutate its first argument however it wants. All mutations are
only ever applied to a copy of the base state.
Pass only a function to create a "curried producer" which relieves you from passing the recipe function every time.
Only plain objects and arrays are made mutable. All other objects are considered uncopyable.
Note: This function is bound to its Immer
instance.
a new state, or the initial state if nothing was modified
The produce
function takes a value and a "recipe function" (whose
return value often depends on the base state). The recipe function is
free to mutate its first argument however it wants. All mutations are
only ever applied to a copy of the base state.
Pass only a function to create a "curried producer" which relieves you from passing the recipe function every time.
Only plain objects and arrays are made mutable. All other objects are considered uncopyable.
Note: This function is bound to its Immer
instance.
a new state, or the initial state if nothing was modified
The produce
function takes a value and a "recipe function" (whose
return value often depends on the base state). The recipe function is
free to mutate its first argument however it wants. All mutations are
only ever applied to a copy of the base state.
Pass only a function to create a "curried producer" which relieves you from passing the recipe function every time.
Only plain objects and arrays are made mutable. All other objects are considered uncopyable.
Note: This function is bound to its Immer
instance.
a new state, or the initial state if nothing was modified
The produce
function takes a value and a "recipe function" (whose
return value often depends on the base state). The recipe function is
free to mutate its first argument however it wants. All mutations are
only ever applied to a copy of the base state.
Pass only a function to create a "curried producer" which relieves you from passing the recipe function every time.
Only plain objects and arrays are made mutable. All other objects are considered uncopyable.
Note: This function is bound to its Immer
instance.
a new state, or the initial state if nothing was modified
The produce
function takes a value and a "recipe function" (whose
return value often depends on the base state). The recipe function is
free to mutate its first argument however it wants. All mutations are
only ever applied to a copy of the base state.
Pass only a function to create a "curried producer" which relieves you from passing the recipe function every time.
Only plain objects and arrays are made mutable. All other objects are considered uncopyable.
Note: This function is bound to its Immer
instance.
the initial state
a new state, or the initial state if nothing was modified
The produce
function takes a value and a "recipe function" (whose
return value often depends on the base state). The recipe function is
free to mutate its first argument however it wants. All mutations are
only ever applied to a copy of the base state.
Pass only a function to create a "curried producer" which relieves you from passing the recipe function every time.
Only plain objects and arrays are made mutable. All other objects are considered uncopyable.
Note: This function is bound to its Immer
instance.
the initial state
a new state, or the initial state if nothing was modified
A utility function that allows defining a reducer as a mapping from action type to case reducer functions that handle these action types. The reducer's initial state is passed as the first argument.
The body of every case reducer is implicitly wrapped with a call to
produce()
from the immer library.
This means that rather than returning a new state object, you can also
mutate the passed-in state object directly; these mutations will then be
automatically and efficiently translated into copies, giving you both
convenience and immutability.
State | (() => State)
: The initial state that should be used when the reducer is called the first time. This may also be a "lazy initializer" function, which should return an initial state value when called. This will be used whenever the reducer is called with undefined
as its state value, and is primarily useful for cases like reading initial state from localStorage
.
(builder: Builder) => void
A callback that receives a builder object to define
case reducers via calls to builder.addCase(actionCreatorOrType, reducer)
.
A utility function that allows defining a reducer as a mapping from action type to case reducer functions that handle these action types. The reducer's initial state is passed as the first argument.
The body of every case reducer is implicitly wrapped with a call to
produce()
from the immer library.
This means that rather than returning a new state object, you can also
mutate the passed-in state object directly; these mutations will then be
automatically and efficiently translated into copies, giving you both
convenience and immutability.
State | (() => State)
: The initial state that should be used when the reducer is called the first time. This may also be a "lazy initializer" function, which should return an initial state value when called. This will be used whenever the reducer is called with undefined
as its state value, and is primarily useful for cases like reading initial state from localStorage
.
An object mapping from action types to case reducers, each of which handles one specific action type.
An array of matcher definitions in the form {matcher, reducer}
.
All matching reducers will be executed in order, independently if a case reducer matched or not.
A "default case" reducer that is executed if no case reducer and no matcher reducer was executed for this action.
Creates a middleware that, after every state change, checks if the new state is serializable. If a non-serializable value is found within the state, an error is printed to the console.
Middleware options.
create a slice that includes enhanced props
Takes a snapshot of the current state of a draft and finalizes it (but without freezing). This is a great utility to print the current state during debugging (no Proxies in the way). The output of current can also be safely leaked outside the producer.
Freezes draftable objects. Returns the original object.
By default freezes shallowly, but if the second argument is true
it will freeze recursively.
Returns any array containing the default middleware installed by
configureStore()
. Useful if you want to configure your store with a custom
middleware
array but still keep the default set.
The default middleware used by configureStore()
.
Returns the action type of the actions created by the passed
createAction()
-generated action creator (arbitrary action creators
are not supported).
The action type used by the action creator.
A higher-order function that returns a function that may be used to check whether an action matches all of the supplied type guards or action creators.
The type guards or action creators to match against.
A higher-order function that returns a function that may be used to check whether an action matches all of the supplied type guards or action creators.
A higher-order function that returns a function that may be used to check whether an action matches any one of the supplied type guards or action creators.
The type guards or action creators to match against.
A higher-order function that returns a function that may be used to check whether an action matches any one of the supplied type guards or action creators.
A higher-order function that returns a function that may be used to check whether an action was created by an async thunk action creator.
A higher-order function that returns a function that may be used to check whether an action was created by an async thunk action creator.
A higher-order function that returns a function that may be used to check whether an action belongs to one of the provided async thunk action creators.
(optional) The async thunk action creators to match against.
A higher-order function that returns a function that may be used to check whether an action belongs to one of the provided async thunk action creators.
Tests if action
is a thunk action
Returns true if the given value is an Immer draft
A higher-order function that returns a function that may be used to check whether an action was created by an async thunk action creator, and that the action is fulfilled.
A higher-order function that returns a function that may be used to check whether an action was created by an async thunk action creator, and that the action is fulfilled.
A higher-order function that returns a function that may be used to check whether an action belongs to one of the provided async thunk action creators, and that the action is fulfilled.
(optional) The async thunk action creators to match against.
A higher-order function that returns a function that may be used to check whether an action belongs to one of the provided async thunk action creators, and that the action is fulfilled.
Tests if action
is a fulfilled thunk action
The default isImmutable
function.
A higher-order function that returns a function that may be used to check whether an action was created by an async thunk action creator, and that the action is pending.
A higher-order function that returns a function that may be used to check whether an action was created by an async thunk action creator, and that the action is pending.
A higher-order function that returns a function that may be used to check whether an action belongs to one of the provided async thunk action creators, and that the action is pending.
(optional) The async thunk action creators to match against.
A higher-order function that returns a function that may be used to check whether an action belongs to one of the provided async thunk action creators, and that the action is pending.
Tests if action
is a pending thunk action
Returns true if the passed value is "plain", i.e. a value that is either
directly JSON-serializable (boolean, number, string, array, plain object)
or undefined
.
The value to check.
Returns true if the passed value is "plain" object, i.e. an object whose
prototype is the root Object.prototype
. This includes objects created
using object literals, but not for instance for class instances.
The value to inspect.
True if the argument appears to be a plain object.
A higher-order function that returns a function that may be used to check whether an action was created by an async thunk action creator, and that the action is rejected.
A higher-order function that returns a function that may be used to check whether an action was created by an async thunk action creator, and that the action is rejected.
A higher-order function that returns a function that may be used to check whether an action belongs to one of the provided async thunk action creators, and that the action is rejected.
(optional) The async thunk action creators to match against.
A higher-order function that returns a function that may be used to check whether an action belongs to one of the provided async thunk action creators, and that the action is rejected.
Tests if action
is a rejected thunk action
A higher-order function that returns a function that may be used to check whether an action was created by an async thunk action creator, and that the action is rejected with value.
A higher-order function that returns a function that may be used to check whether an action was created by an async thunk action creator, and that the action is rejected with value.
A higher-order function that returns a function that may be used to check whether an action belongs to one of the provided async thunk action creators, and that the action is rejected with value.
(optional) The async thunk action creators to match against.
A higher-order function that returns a function that may be used to check whether an action belongs to one of the provided async thunk action creators, and that the action is rejected with value.
Tests if action
is a rejected thunk action with value
Creates a Redux store that holds the state tree.
We recommend using configureStore
from the
@reduxjs/toolkit
package, which replaces createStore
:
https://redux.js.org/introduction/why-rtk-is-redux-today
The only way to change the data in the store is to call dispatch()
on it.
There should only be a single store in your app. To specify how different
parts of the state tree respond to actions, you may combine several reducers
into a single reducer function by using combineReducers
.
A function that returns the next state tree, given the current state tree and the action to handle.
A Redux store that lets you read the state, dispatch actions and subscribe to changes.
Creates a Redux store that holds the state tree.
We recommend using configureStore
from the
@reduxjs/toolkit
package, which replaces createStore
:
https://redux.js.org/introduction/why-rtk-is-redux-today
The only way to change the data in the store is to call dispatch()
on it.
There should only be a single store in your app. To specify how different
parts of the state tree respond to actions, you may combine several reducers
into a single reducer function by using combineReducers
.
A function that returns the next state tree, given the current state tree and the action to handle.
A Redux store that lets you read the state, dispatch actions and subscribe to changes.
Serializes an error into a plain object. Reworked from https://github.com/sindresorhus/serialize-error
Get the underlying object that is represented by the given draft
A hook that can access store builder of current store. Use store builder for adding reducers or slides dynamically
create a component wrapper that calls buildCallbacks
create a component wrapper that calls buildCallbacks
create a component wrapper that calls buildCallbacks
create a component wrapper that calls buildCallbacks
create a component wrapper that calls buildCallbacks
create a component wrapper that calls buildCallbacks
inject slices to the component
Generated using TypeDoc
Infer action type from a reducer function.