encapsulation
Keeping a component's internal data and details behind a small public interface.
In more detail
Callers use the component's methods, props or functions instead of reaching into its internals. That lets the internals change without breaking the code that uses them. Languages enforce it to different degrees, from strict private members to naming conventions.
Example
A React component that exposes a curated imperative handle instead of its DOM node, or a custom hook that returns named actions, is encapsulated.Related terms
- useImperativeHandle — The React hook that lets a component choose exactly which methods its parent gets through a ref, instead of the raw DOM node.
- custom hook — Your own function whose name starts with use and that calls other hooks, packaging stateful logic so several components can reuse it.
Taught in
- useImperativeHandle: Controlled Ref Forwarding Boundaries — React 19 & Modern Component Architecture
- Compound Components: Inversion of Control with Context — React 19 & Modern Component Architecture
- Higher-Order Components And Render Props: Tradeoff Analysis — React 19 & Modern Component Architecture
- Rules of Hooks: Call Order, Hook Lists, And Fiber Storage — React 19 & Modern Component Architecture
- Custom Hook Composition: Encapsulating Reactive Logic — React 19 & Modern Component Architecture
- Creating Event Listener Hooks with Clean Teardown Logic — React 19 & Modern Component Architecture
- Accessible Headless Primitives: ARIA, Focus, And Keyboard — React 19 & Modern Component Architecture
- Classes, Objects And Two Stacks — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep