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

React · API reference · all subjects

advanced hooks: transitions & async

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

useOptimistic hook for optimistic updates

useOptimistic hook receives a currentValue and returns [optimisticValue, setOptimisticValue]. It immediately renders the optimistic value while an async request is in progress. When the update finishes or errors, React automatically switches back to the currentValue. Used to show users instant feedback while requests are submitting.

useDeferredValue initialValue option

useDeferredValue now accepts an optional second parameter 'initialValue'. When initialValue is provided, useDeferredValue will return it as the value for the initial render of the component, and schedules a re-render in the background with the deferredValue returned.

Actions automatically manage form submission and state

Actions provide: Pending state that starts at request beginning and resets when the final state update commits. Optimistic updates via useOptimistic hook. Error handling via Error Boundaries with automatic revert of optimistic updates on error. Form reset automatically after successful submission when passing functions to <form> action prop.

startTransition inside onClick handlers for transitions

The `startTransition` function from React can be called inside event handlers like onClick to mark state updates as transitions. This allows View Transitions to animate the DOM changes.

addTransitionType function for custom transition types

The addTransitionType function (imported from react) sets the transition type within a startTransition call. This type is then used to select CSS animations via the share prop on ViewTransition components. Example: startTransition(() => { addTransitionType('nav-forward'); navigate(url); })

Automatic Effect dependencies reinforces correct mental model

Automatically inserting dependencies into Effects makes them easier to write and understand by forcing developers to think in terms of what the Effect does rather than component lifecycles. This helps shift perspective from the component's lifecycle view to the Effect's synchronization view.

Give your agent this brain