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

Taught in

References