Please enable JavaScript.
Coggle requires JavaScript to display documents.
React - Advanced Guides (APIs (Refs and the DOM (API (Callback refs…
React - Advanced Guides
APIs
Refs and the DOM
API
-
-
-
Refs objects
current
property
-
References the underlying DOM node or the mounted instance of the child component when the parent component is mounted
-
-
-
-
Context
Motivation
Allows for passing data through a component tree without having to explicitly pass individual props down
-
-
API
-
Context.Provider
-
Takes a value
prop
-
-
:link: Values are compared using the same algorithm as Object.is
-
Values created inside render
methods may trigger re-rendering of consumers if the parent of provider re-renders
-
-
-
-
-
-
Context.displayName
-
Sets the display name of Context.Provider
and Context.Consumer
components of the context type in React DevTools
-
Forwarding refs
Use cases
-
Higher-order components
-
A ref passed to a higher-order component would refer to the outermost container and not to the wrapped component
Container component (defined using React.forwardRef()
) should pass their ref parameter as a regular prop to the wrapped component
-
API
React.forwardRef()
-
-
Any refs passed to the component from the parent would be available through the ref
parameter to the receiving component
Portals
-
API
ReactDOM.createPortal(child, container)
-
-
-
-
-
Reconciliation
-
Algorithm
-
-
Finer points
-
-
Keys should be stable, predictable, and unique
-
-
-
-