imperative programming
A style of programming where you give explicit step-by-step commands, such as find this element and set its text.
In more detail
Most general-purpose code, such as loops that change variables, is imperative. It gives full control but makes you responsible for every step.
Example
React code is mostly declarative; focusing an input or scrolling a list are imperative jobs done through refs and useImperativeHandle.Related terms
- declarative programming — A style of programming where you describe the result you want and let the system work out the steps, rather than giving each step yourself.
- useImperativeHandle — The React hook that lets a component choose exactly which methods its parent gets through a ref, instead of the raw DOM node.
- ref — A React handle that points at a real DOM element, so code can focus it, measure it or attach listeners.
Taught in
- useRef Mechanics: DOM References And Mutable Persistent State — React 19 & Modern Component Architecture
- useImperativeHandle: Controlled Ref Forwarding Boundaries — React 19 & Modern Component Architecture
- The React Compiler: Automated Memoization Under The Hood — React 19 & Modern Component Architecture