inversion of control
A design in which a piece of code gives up control of some decisions, such as how its dependencies are created or what it renders, to the code around it.
In more detail
In Java frameworks such as Spring, a container creates objects and hands each class the collaborators it needs, usually through dependency injection, instead of each class constructing its own. In component libraries, a component lets the code using it supply pieces through composition, slots or render functions instead of deciding every layout through props. Both keep one part from hard-coding choices that belong elsewhere.
Example
Compound components, slots and render props all invert control in React.Related terms
- composition — Building a component out of smaller components that the consumer assembles, instead of configuring one big component with flags.
- slot — A place in a component's layout that the consumer fills with their own content, either through a named prop such as icon or through a Slot component.
- dependency injection — Giving an object the collaborators it needs from outside, usually through its constructor, instead of letting it create or look them up itself.
- Spring bean — An object that the Spring container creates, configures and manages, and can inject into other beans.
- application context — The running Spring container: the object that holds every bean for an application and manages their creation and shutdown.
- compound component — A set of components designed to be used together, such as Tabs, Tabs.Trigger and Tabs.Panel, that share state behind the scenes.
- render prop — A prop whose value is a function the component calls to decide what to display, passing in its internal data.
Taught in
- Component API Ergonomics: Composition vs Boolean Config Props — Design Systems & Component Engineering
- Dependency Injection And The IoC Container — Modern Java: Virtual Threads & High-Throughput Services
- Spring Boot Auto Configuration — Modern Java: Virtual Threads & High-Throughput Services
- useContext in Depth: Scoping, Consumer Subscription Costs — React 19 & Modern Component Architecture
- Compound Components: Inversion of Control with Context — React 19 & Modern Component Architecture
- Slot Patterns And Headless UI Architecture in React — React 19 & Modern Component Architecture