Custom Hooks in React
15 questions · 12 min · Medium
Test your knowledge of React Components and Props with 15 questions covering functional components, JSX, props, passing data, children, reusability, and component communication.
No sign-up needed · Last updated:
Score: 0 00:00
Create a free account to keep your scores and track your progress. It is optional.
15 questions · 12 min · Medium
20 questions · 15 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
B. A reusable piece of UI and logic
A React component is a reusable building block that can contain UI, logic, and behavior.
A. Functional component
Modern React primarily uses JavaScript functions as components, often called functional components.
A. function Welcome() { return <h1>Hello</h1>; }
A React functional component can be defined as a JavaScript function that returns JSX.
A. Properties used to pass data to components
Props, short for properties, allow data to be passed from a parent component to a child component.
A. Through the props parameter
A functional component receives props as its parameter, which can be accessed using expressions such as props.name.
A. <User name="John" />
Props are passed to components using JSX attributes, such as name="John".
B. <User name={userName} />
Curly braces are used in JSX to evaluate JavaScript expressions and pass their values as props.
C. No, props should be treated as read-only
React components should not directly modify the props they receive. The parent component controls the values passed through props.
B. It represents content placed between a component's opening and closing tags
The children prop contains whatever is placed between a component's opening and closing JSX tags.
A. <Card>Hello</Card>
When content is placed between <Card> and </Card>, React makes that content available to the Card component through the children prop.
B. A parent can pass data to a child through props
React commonly uses one-way data flow, where a parent passes data and functions to child components through props.
A. By passing a callback function as a prop
A parent can pass a function as a prop, allowing the child to call that function and communicate an event or value back to the parent.
B. Component names should normally start with an uppercase letter
React uses capitalization to distinguish user-defined components such as <UserProfile /> from built-in HTML elements such as <div />.
B. They allow UI and logic to be reused
Reusable components help developers avoid duplication and make applications easier to maintain and organize.
A. function User({ name }) { return <h1>{name}</h1>; }
Object destructuring allows a component to extract individual props directly from the props parameter.