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 · all subjects

createslice

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

createSlice combines reducers, action creators, and action types

createSlice() accepts an object of reducer functions, a slice name, and an initial state value, and automatically generates a slice reducer with corresponding action creators and action types.

createSlice uses Immer for immutable updates with mutating syntax

createSlice lets you write reducers that use the Immer library to enable writing immutable updates using 'mutating' JavaScript syntax like state.value = 123, with no spreads needed. It also automatically generates action creator functions for each reducer and generates action type strings internally based on reducer names.

createSlice example with todos

Example using createSlice: import { createSlice } from '@reduxjs/toolkit'; const todosSlice = createSlice({ name: 'todos', initialState: [], reducers: { todoAdded(state, action) { state.push({ id: action.payload.id, text: action.payload.text, completed: false, }); }, todoToggled(state, action) { const todo = state.find((todo) => todo.id === action.payload); todo.completed = !todo.completed; }, }, }); export const { todoAdded, todoToggled } = todosSlice.actions; export default todosSlice.reducer;

Give your agent this brain