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

utility functions

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

RTK Query invalidation requires active subscription to refetch

If a mutation invalidates tags but no visible refetch occurs, check whether anything is still subscribed to that cache entry. Invalidation only triggers refetches for queries that are currently being used and subscribed to.

Debug Redux flow in order: action -> reducer -> selector -> render

When a component looks wrong, verify the problem in sequence: first check that the action fired, then verify the reducer updated state correctly, then check the selector returns the expected value, finally check the render boundary. This systematic debugging approach isolates whether the issue is in dispatch, reducer, selector, or component rendering.

Avoid creating unstable objects in selectFromResult

In RTK Query selectFromResult option, do not create new object or array references on every call, such as spreading arrays with [...data] or wrapping data in new objects. Return the original data reference directly: selectFromResult: ({ data = [] }) => ({ posts: data }). New references defeat memoization and cause unnecessary rerenders even when underlying data hasn't changed.

createDraftSafeSelector export

createDraftSafeSelector is exported as an alias to createSelector from reselect, providing a type-safe selector creator that works with draft state in reducers.

setupListeners must be called after configureStore

The setupListeners function from @reduxjs/toolkit/query must be called with store.dispatch to configure listeners using the provided defaults for rtk-query to function properly.

setupListeners enables caching, invalidation, polling features

Calling setupListeners with store.dispatch configures listeners using the provided defaults, which enables caching, invalidation, polling, and other useful features of rtk-query.

createSelector is re-exported from Reselect

The createSelector() utility from the Reselect library is re-exported from Redux Toolkit for ease of use.

copyWithStructuralSharing function

copyWithStructuralSharing is an exported function with signature: <T>(oldObj: any, newObj: T): T. It takes an old object and new object, returning the new object with structural sharing applied.

Give your agent this brain