# Short-lived mutability
I define short-lived mutability as a piece of imperative code that mutates stuff to get the job done within a single microtask, under the following rules:
- Everything that is mutated is created within that microtask.
- Once the microtask is done, the mutated stuff is no longer mutable.
- DOM manipulation. In most cases, DOM that is being mutated exists before the microtask runs, and can still be mutated after the microtask is done.
React Hooks — Calling a React hook mutates the functional components’s internal state to be able to store state in a place managed by React. A global dispatcher allows the hook implementation to be aware of what component is currently being worked on, without requiring callers to explicitly pass around internal data structure. For more information on this mechanism see Getting Closure on Hooks.
Immediate mode GUI — This design pattern allows one to write an imperative yet declarative build a GUI. Every frame, the GUI-declaration code is executed, where the caller “declares” what GUI elements should be shown, and the result is rendered afterwards. For a quick example, see the first part of the mCoding’s video “Pythonizing Imgui (feat. Cython) and contributing to open source”.
A pattern emerges:
- To the eyes of an outsider, nothing is being mutated.
- To the eyes of an insider, we are writing straightforward code that is straight up mutating things, yet due to its short-lived nature, the imperative code has no long-term effects.
So now it sounds to me like “short-lived imperative logic, functional core, imperative shell.”