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

configurestore

67 notes in this subject, read out of this brain and free to use. This is page 2 of 2.

Example: Store setup with configureStore

Store setup can be simplified with configureStore. Example: import { configureStore } from '@reduxjs/toolkit' import todosReducer from '../features/todos/todosSlice' import filtersReducer from '../features/filters/filtersSlice' export const store = configureStore({ reducer: { todos: todosReducer, filters: filtersReducer, }, })

makeStore function pattern for Next.js App Router

In Next.js App Router applications, instead of defining a global Redux store, create a makeStore function that returns a new store instance for each request. This prevents store contamination across simultaneous requests on the server. The makeStore function uses configureStore internally and allows type inference of RootState and AppDispatch from the store's return type.

Per-route state management in Next.js App Router

When using next/navigation for client-side SPA-style navigation with a Redux store in the layout, route-specific data must be reset on each route change. Use a useRef to track initialization and dispatch initialization actions when the component first renders, which occurs on each route change. Initialize store state in the component render function, not useEffect, to ensure hydration consistency.

StoreProvider client component for Next.js

Create a 'use client' component that instantiates the Redux store using makeStore and provides it to child components via the React-Redux Provider. Use useState with a lazy initializer function to ensure the store is created exactly once per request. The component wraps its children with Provider and passes the store instance.

Why client components are required for Redux in Next.js App Router

Any component that interacts with the Redux store (creating it, providing it, reading from it, or writing to it) must be a client component because accessing the store requires React context, which is only available in client components. Server components (RSCs) cannot read or write the Redux store.

Initializing store with data in Next.js

To initialize the Redux store with data from a parent component, define that data as a prop on the client StoreProvider component. Inside StoreProvider, after creating the store with makeStore, dispatch a Redux action to set the initial data. This must happen in the lazy initializer function passed to useState, not in useEffect, to avoid hydration errors.

Redux architecture recommendations for Next.js App Router

For Next.js App Router applications, use Redux only for globally shared, mutable data. Use Next.js state (search params, route parameters), React context, and React hooks for all other state management. This differs from SPA applications where it is common to store both mutable and immutable data in a large global store.

Give your agent this brain