Functional components versus class components?
Function components use hooks and are standard for new code; class components use lifecycle methods and remain supported.
The question library
Explore practical questions, clear explanations, and code examples across developer technologies.
Showing 3109–3120 of 3610 questions
Function components use hooks and are standard for new code; class components use lifecycle methods and remain supported.
Lifting state up moves shared state to the closest common parent of components that need it.
Data generally flows from parent to child through props; children communicate changes using callbacks supplied by parents.
TypeScript adds static type checking to JavaScript and documents component contracts during development.
Define a type or interface for the props and use it as the component parameter type.
Provide a generic such as useState<User | null>(null) when the initial value does not express the full state type.
Use React.ChangeEvent<HTMLInputElement> for a conventional input change handler.
The children prop represents content nested between a component's opening and closing tags.
Both generally render no visible content, but they have different JavaScript meanings and may represent different application states.
A portal renders children into a DOM node outside the parent DOM hierarchy while preserving React context and event propagation.
A ref stores a mutable value across renders without causing a re-render when changed.
Prop drilling passes data through layers that do not use it so a deeper component can access it.