new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Redux Toolkit · API · all subjects

actioncreatormiddleware/createactioncreatorinvariantmiddleware

4 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

createActionCreatorInvariantMiddleware function signature

createActionCreatorInvariantMiddleware is a function that creates an instance of the action creator check middleware. It accepts an optional options object of type ActionCreatorInvariantMiddlewareOptions and returns a middleware instance. The function detects if an action creator has been mistakenly dispatched instead of being called, which catches the common mistake of calling dispatch(actionCreator) instead of dispatch(actionCreator()).

createActionCreatorInvariantMiddleware example with custom isActionCreator

This example shows how to create an action creator middleware with a custom isActionCreator function that considers all functions with a static type property to be action creators: ```ts import { configureStore, createActionCreatorInvariantMiddleware, Tuple, } from '@reduxjs/toolkit' import reducer from './reducer' const isActionCreator = ( action: unknown, ): action is Function & { type: unknown } => typeof action === 'function' && 'type' in action const actionCreatorMiddleware = createActionCreatorInvariantMiddleware({ isActionCreator, }) const store = configureStore({ reducer, middleware: () => new Tuple(actionCreatorMiddleware), }) ```

getDefaultMiddleware includes createActionCreatorInvariantMiddleware

The createActionCreatorInvariantMiddleware is automatically included by getDefaultMiddleware, so you will most likely not need to call createActionCreatorInvariantMiddleware yourself.

Middleware type changed in Redux 5.0

In Redux 5.0, the Middleware type signature changed. The next parameter is now typed as (action: unknown) => unknown instead of the full dispatch type. The action parameter is now typed as unknown instead of being based on the action type. You must use type guards like isAction(action) or actionCreator.match(action) to safely narrow types before accessing fields.

Give your agent this brain