Unit 2: Component Design and Styling - Practice Quiz

INT252 — Web App Development With Reactjs 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is a functional component in React?

Functional components Easy
A. A JavaScript function that returns React elements
B. A database function that stores application data
C. A CSS file that defines component styles
D. An HTML file loaded directly by the browser

2 How should the name of a React functional component normally begin?

Functional components Easy
A. With a number
B. With a hyphen
C. With a lowercase letter
D. With an uppercase letter

3 What are props primarily used for in React?

Props-driven component reusability Easy
A. Adding global CSS rules to a page
B. Passing data from a parent to a child
C. Storing data in the browser permanently
D. Connecting directly to a database

4 How do props help make a component reusable?

Props-driven component reusability Easy
A. They force the component to use fixed content
B. They let the component display different supplied data
C. They prevent the component from being rendered twice
D. They automatically create a new database table

5 Which special prop commonly contains elements nested inside a React component?

Component composition patterns Easy
A. children
B. innerHTML
C. nestedItems
D. contentType

6 What does component composition mean in React?

Component composition patterns Easy
A. Writing every interface in one large component
B. Combining all style rules into one selector
C. Building larger interfaces from smaller components
D. Replacing JSX with plain database queries

7 Which is the best example of a reusable component abstraction?

Reusable component abstractions Easy
A. A unique database query for each user
B. A complete application stored in one component
C. A fixed heading written separately on every page
D. A configurable Button used on many pages

8 Which JavaScript operator is commonly used to render one of two React elements based on a condition?

Conditional rendering strategies Easy
A. The increment operator value++
B. The assignment operator value = A
C. The remainder operator value % B
D. The ternary operator condition ? A : B

9 What does {isVisible && <Panel />} do in JSX?

Conditional rendering strategies Easy
A. It renders Panel exactly two times
B. It permanently removes Panel from the project
C. It renders Panel when isVisible is falsy
D. It renders Panel when isVisible is truthy

10 What does lifting state up mean in React?

Lifting state up in component hierarchies Easy
A. Moving shared state to a common parent
B. Moving props into the browser address bar
C. Moving JSX into the public HTML file
D. Moving CSS rules into an external file

11 After state is lifted to a parent, how can a child usually request an update?

Lifting state up in component hierarchies Easy
A. By directly changing the parent's local variable
B. By editing the parent's JSX source file
C. By calling a callback received through props
D. By replacing the application's HTML document

12 Which design usually gives a React component a clear responsibility boundary?

Defining component responsibility boundaries Easy
A. Giving it direct access to all state
B. Giving it one focused purpose
C. Giving it every application feature
D. Giving it unrelated layout and data tasks

13 Which JSX attribute is normally used to apply a CSS class to an element?

Styling approaches in React applications Easy
A. classList
B. cssName
C. styleClass
D. className

14 What does the Tailwind CSS class text-center do?

Tailwind CSS fundamentals Easy
A. It adds space below the text
B. It centers the text horizontally
C. It makes the text bold
D. It changes the text to uppercase

15 What is the main idea of utility-first styling?

Utility-first styling methodology Easy
A. Combining small classes for individual style rules
B. Avoiding reusable classes in all components
C. Writing one large style block for every page
D. Using only inline JavaScript for visual design

16 In the Tailwind class md:text-lg, when is text-lg applied by default?

Responsive design using Tailwind breakpoints Easy
A. At the md breakpoint and larger
B. At every size without restriction
C. Only when the mouse is hovering
D. Only below the md breakpoint

17 What is a good way to reuse the same styled button across a React application?

Reusable UI styling patterns Easy
A. Use a different style on every page
B. Create a shared Button component
C. Place every button inside the root component
D. Copy the full button markup everywhere

18 What should the alt attribute of an informative image provide?

Accessibility fundamentals Easy
A. A concise description of the image
B. A command that downloads the image
C. A link to the application's home page
D. A list of the image's CSS classes

19 Why should a form input have an associated label?

Accessibility fundamentals Easy
A. To hide the input from screen readers
B. To submit the form without a button
C. To identify the input for all users
D. To automatically validate every value

20 Which semantic HTML element should usually contain the primary content of a page?

Semantic HTML practices in React Easy
A. <br>
B. <b>
C. <main>
D. <span>

21 A functional component receives an onSave callback and should call it only when the user clicks a button. Which JSX is correct?

Functional components Medium
A. <button onClick={onSave()}>Save</button>
B. <button onClick={onSave}>Save</button>
C. <button onClick={() => onSave}>Save</button>
D. <button onClick="onSave">Save</button>

22 A ProductCard must display different products and notify its parent when one is selected. Which prop design best supports reuse?

Props-driven component reusability Medium
A. <ProductCard product={product} onSelect={handleSelect} />
B. <ProductCard productId="42" selected="true" />
C. <ProductCard onClick={handleSelect(product)} />
D. <ProductCard data={window.currentProduct} />

23 A reusable Panel should provide a border and padding while allowing callers to place arbitrary content inside it. Which API is most appropriate?

Component composition patterns Medium
A. Store the content in local component state
B. Read the content from a global variable
C. Import every possible child component
D. Accept the content through children

24 A reusable text input must work with a parent-managed form. Which interface makes the input a suitable controlled abstraction?

Reusable component abstractions Medium
A. Accept defaultValue and ignore later updates
B. Accept value and onChange props
C. Keep the value only in internal state
D. Read the value directly from the DOM

25 Consider {items.length && <List items={items} />}. What should replace it if nothing should appear when the array is empty?

Conditional rendering strategies Medium
A. Boolean(items) && <List items={items} />
B. items.length > 0 && <List items={items} />
C. items.length >= 0 && <List items={items} />
D. items.length || <List items={items} />

26 A SearchBox sibling controls the products shown by a ProductList. Where should the search query usually be stored?

Lifting state up in component hierarchies Medium
A. In each sibling independently
B. Inside SearchBox only
C. Inside ProductList only
D. In their closest common parent

27 A UserProfile component fetches data, handles routing, formats dates, and renders a large form. Which refactoring best improves responsibility boundaries?

Defining component responsibility boundaries Medium
A. Move all behavior into event handlers
B. Duplicate the component for each route
C. Move every task into one custom hook
D. Split data logic and focused UI components

28 Two components import CSS Modules that both define a .title class. What is the expected result?

Styling approaches in React applications Medium
A. Both classes become globally shared
B. Each title receives a locally scoped class
C. React removes one duplicate class
D. The later import overrides both titles

29 Which Tailwind class list gives a button horizontal padding of 1rem and vertical padding of 0.5rem using the default spacing scale?

Tailwind CSS fundamentals Medium
A. px-4 py-2
B. p-4 gap-2
C. pl-4 pt-2
D. mx-4 my-2

30 A button variant is currently built as `bg-${color}-600`. Production CSS sometimes omits the generated class. What is the best utility-first solution?

Utility-first styling methodology Medium
A. Replace the class with an inline event
B. Map variants to complete class strings
C. Build every utility name at runtime
D. Add the color through an element ID

31 A card should be full width by default, half width on medium screens, and one-third width on large screens. Which classes implement this?

Responsive design using Tailwind breakpoints Medium
A. w-1/3 md:w-1/2 lg:w-full
B. w-full md:w-1/2 lg:w-1/3
C. w-full sm:w-1/3 md:w-1/2
D. sm:w-full md:w-full lg:w-1/2

32 Several buttons share base Tailwind classes but differ by primary, danger, or secondary variants. Which approach is most maintainable?

Reusable UI styling patterns Medium
A. Select complete variant classes in one component
B. Place all variants in global element selectors
C. Generate arbitrary class names from user input
D. Repeat every class at each call site

33 A form displays the text Email address next to an email input. Which implementation reliably associates the label with the field?

Accessibility fundamentals Medium
A. <span>Email address</span><input name="email" />
B. <label htmlFor="email">Email address</label><input id="email" />
C. <label>Email address</label><input id="email" />
D. <p id="email">Email address</p><input name="email" />

34 A clickable control submits a search form. Which element best communicates its purpose and supplies native keyboard behavior?

Semantic HTML practices in React Medium
A. <span role="link">Search</span>
B. <a onClick={submit}>Search</a>
C. <button type="submit">Search</button>
D. <div onClick={submit}>Search</div>

35 A component receives price and quantity props and only needs to display their product. How should total usually be produced?

Functional components Medium
A. Store the product in unrelated global state
B. Copy both props into separate local states
C. Set state on every component rendering
D. Compute price * quantity during rendering

36 A reusable Avatar should display Guest when no name prop is provided. Which functional component signature applies that default cleanly?

Props-driven component reusability Medium
A. function Avatar(props = name: 'Guest') { ... }
B. function Avatar(name = 'Guest') { ... }
C. function Avatar({ name = 'Guest' }) { ... }
D. function Avatar({ name }) { name ||= props; }

37 A page must show an error message when a request fails, a spinner while loading, and content after successful loading. Which structure is clearest?

Conditional rendering strategies Medium
A. Render all three and hide them with event handlers
B. Place every condition inside one class name
C. Use early returns for error, loading, and content
D. Store JSX elements permanently in component state

38 Two sibling inputs display Celsius and Fahrenheit values and must remain synchronized. Which state design is most appropriate?

Lifting state up in component hierarchies Medium
A. Update one input only when the form submits
B. Keep one shared temperature in their parent
C. Give each input unrelated temperature state
D. Read both values from the DOM after rendering

39 A navigation menu should be hidden on small screens and use flex layout from the medium breakpoint upward. Which classes are correct?

Responsive design using Tailwind breakpoints Medium
A. flex md:hidden
B. md:hidden lg:block
C. invisible sm:flex
D. hidden md:flex

40 An icon-only button closes a dialog. Which implementation gives it an accessible name without making the decorative icon separately announced?

Accessibility fundamentals Medium
A. <button aria-label="Close"><svg aria-hidden="true" /></button>
B. <div aria-label="Close"><svg aria-hidden="true" /></div>
C. <button><svg title="Close" /></button>
D. <button role="img"><svg aria-label="Close" /></button>

41 A counter must increase by exactly 2 when incrementTwice is called, including when React batches state updates. Which implementation is correct?

JSX
function Counter() {
  const [count, setCount] = useState(0);
  // incrementTwice is defined here
}

Functional components Hard
A. const incrementTwice = () => { setCount(c => c + 1); setCount(c => c + 1); };
B. const incrementTwice = () => { setCount(count + 2); setCount(count); };
C. const incrementTwice = () => { setCount(count + 1); setCount(count + 1); };
D. const incrementTwice = () => { setCount(++count); setCount(++count); };

42 A reusable list must support unrelated item schemas, preserve item state during reordering, and allow callers to control rendering. Which prop API best satisfies these requirements?

Props-driven component reusability Hard
A. <DataList items={items} getKey={item => item.uuid} renderItem={item => <Row item={item} />} />
B. <DataList items={items} renderItem={(item, index) => <Row key={index} item={item} />} />
C. <DataList items={items} keyField="uuid" rowType="Row" nameField="title" />
D. <DataList items={items.map(item => ({ ...item, key: Math.random() }))} />

43 A Dialog must own focus management and layout while allowing callers to provide arbitrary header, body, and footer content. Which design most directly applies composition without making Dialog depend on application-specific data?

Component composition patterns Hard
A. <Dialog renderMode="record" recordId={record.id} actionName="remove" />
B. <Dialog titleText="Delete" bodyText="Confirm" buttonText="Remove" />
C. <Dialog header={<Title />} footer={<Actions />}> <Content /> </Dialog>
D. <Dialog data={record} type="delete" showCancel={true} showIcon={true} />

44 Several visually unrelated components require the same disclosure state, Escape-key behavior, and ARIA prop generation, but they must produce different markup. Which abstraction is most appropriate?

Reusable component abstractions Hard
A. A custom hook returning state, actions, and prop-getter functions
B. A shared component containing fixed disclosure HTML and CSS
C. A utility function that calls React hooks outside a component
D. A module-level singleton storing the currently open disclosure

45 Given {unreadCount && <Badge>{unreadCount}</Badge>}, users see an unwanted 0 when unreadCount is zero. Which replacement hides the badge without rendering the numeric value?

Conditional rendering strategies Hard
A. {Boolean(unreadCount) && unreadCount && <Badge />}
B. {unreadCount || <Badge>{unreadCount}</Badge>}
C. {unreadCount ?? <Badge>{unreadCount}</Badge>}
D. {unreadCount > 0 ? <Badge>{unreadCount}</Badge> : null}

46 Two sibling temperature inputs must remain synchronized, but the currently edited input must temporarily accept incomplete text such as - or 1.. What should their nearest common parent store?

Lifting state up in component hierarchies Hard
A. Independent Celsius and Fahrenheit numbers updated by separate handlers
B. Both raw strings plus effects that continuously synchronize each other
C. Only a parsed Celsius number recalculated after every individual keystroke
D. The raw input string and the scale of the most recently edited input

47 A page fetches orders, a list lays them out, and each row exposes a retry action. The retry requires page-level authentication and cache invalidation. Which boundary best separates responsibilities?

Defining component responsibility boundaries Hard
A. The list reads global credentials and discovers retry endpoints from each rendered row
B. Each row owns authentication, cache invalidation, fetching, and its visual presentation
C. The page renders every row detail directly and avoids list or row components entirely
D. The page owns fetching and retry orchestration; rows receive order data and callbacks

48 A CSS Module defines .root, .primary, and .danger. The component receives variant as either "primary" or "danger". Which expression correctly combines the scoped classes?

Styling approaches in React applications Hard
A. className="styles.root styles[variant]"
B. className={{styles[variant]}}
C. className={{variant}}
D. className={${styles.root} styles.variant}

49 A production build omits colors generated by className={bg-${color}-600}, although the classes appear during development. Assuming color comes from a fixed supported set, what is the most robust correction?

Tailwind CSS fundamentals Hard
A. Move the interpolated class expression into a separate JavaScript utility file
B. Map each supported color to a complete literal class such as bg-red-600
C. Prefix the dynamic expression with tailwind: before assigning className
D. Store only the numeric shade in state and interpolate the color statically

50 An application repeats a long button class list and must support consistent variants, disabled behavior, and loading indicators. Which refactoring best preserves utility-first styling while centralizing the design contract?

Utility-first styling methodology Hard
A. Create a Button component with static utility strings selected by typed variant props
B. Allow each caller to construct utility names dynamically from color and size strings
C. Replace every utility with one global .button rule containing all possible declarations
D. Copy the existing utility list and document that callers must keep variants synchronized

51 Using Tailwind's default mobile-first breakpoints, when is an element with hidden md:flex lg:hidden xl:flex displayed?

Responsive design using Tailwind breakpoints Hard
A. Below md, and from lg to below xl only
B. Only from lg to below xl because hidden resets at lg
C. From md upward because the first responsive display rule wins
D. From md to below lg, and again at xl and above

52 A reusable component uses className={clsx("px-4 py-2", className)}. A caller passes "px-2", but the intended override is unreliable because conflicting Tailwind utilities are both present. Which solution best expresses override semantics?

Reusable UI styling patterns Hard
A. Reverse the arguments to clsx so caller classes always control the cascade
B. Add !important to every utility in the component's default class collection
C. Merge the result with a Tailwind-aware conflict resolver such as twMerge
D. Sort all class tokens alphabetically before assigning the resulting class string

53 A validation error is displayed immediately after an email field. Which markup gives the input an accessible name, exposes invalid state, and associates the error message with the field?

Accessibility fundamentals Hard
A. <label>Email</label><input name="email" invalid="true" /><p className="error">Invalid email</p>
B. <label htmlFor="email-error">Email</label><input id="email" /><p aria-invalid="true">Invalid email</p>
C. <label htmlFor="email">Email</label><input id="email" aria-invalid="true" aria-describedby="email-error" /><p id="email-error" role="alert">Invalid email</p>
D. <span id="email">Email</span><input aria-label="email-error" /><p role="status">Invalid email</p>

54 A card navigates to an article when its main area is activated, but it also contains an independent Save button. Which structure avoids invalid nested interactive controls while preserving both actions?

Semantic HTML practices in React Hard
A. Render one outer <button> for navigation and place a second Save <button> inside it
B. Use an <article> with a heading link expanded by CSS and a sibling <button> layered above it
C. Wrap the entire <article> and its nested Save <button> inside a single <a> element
D. Render the card as a <div onClick> and stop propagation from a nested clickable <span>

55 The following component unexpectedly resets Editor state whenever framed changes:

JSX
return framed
  ? <section className="frame"><Editor /></section>
  : <Editor />;



Which redesign preserves Editor state while still toggling the frame?

Component composition patterns Hard
A. return framed ? <section><Editor /></section> : <Fragment><Editor /></Fragment>;
B. return <section className={framed ? "frame" : undefined}><Editor /></section>;
C. return framed ? <section><Editor key="a" /></section> : <Editor key="a" />;
D. return <>{framed && <section />}<Editor key={framed} /></>;

56 While remaining in edit mode, the application may switch directly from record A to record B. The form initializes local state from record, but currently retains A's edits. Which rendering strategy intentionally resets the form for B?

Conditional rendering strategies Hard
A. <RecordForm key={record.id} record={record} />
B. <RecordForm record={record} reset={record !== record} />
C. <RecordForm key="record" record={{ ...record }} />
D. record && <RecordForm key={true} record={record} />

57 A parent fetches an updated array of products while two children share the current selection. Product objects may be replaced even when their IDs remain stable. What should the parent store as the authoritative selection?

Lifting state up in component hierarchies Hard
A. The selected product object, preserving its original reference across all fetches
B. The selected product ID, deriving the current product from the latest array
C. A copied selected product in each child, synchronized through separate effects
D. The selected array index, recalculated only when a child changes its selection

58 A server-rendered component chooses "desktop" or "mobile" classes by reading window.innerWidth during render. The difference is purely visual. Which approach best avoids hydration mismatches and resize synchronization code?

Styling approaches in React applications Hard
A. Render one structure and express the layout change with CSS media queries
B. Initialize desktop markup on the server and replace it with mobile markup after hydration
C. Store the viewport width in a module variable shared by all rendered component instances
D. Read window.innerWidth only when typeof window !== "undefined" during render

59 A custom horizontal tab interface uses elements with role="tab". Which interaction and ARIA model most closely follows the standard tabs pattern?

Accessibility fundamentals Hard
A. Use aria-expanded on every tab, Escape for movement, and links to unnamed tab panels
B. Keep tabs unfocusable, handle mouse clicks only, and announce selection through title
C. Use roving tabIndex, arrow-key navigation, aria-selected, and aria-controls references
D. Give every tab tabIndex="0", use Tab for navigation, and place state in aria-checked

60 Consider this memoized component:

JSX
const SaveButton = React.memo(
  function SaveButton({ label, onSave }) {
    return <button onClick={onSave}>{label}</button>;
  },
  (prev, next) => prev.label === next.label
);



The parent passes an onSave callback that closes over the current draft. Why can clicking the button save an older draft when the label is unchanged?

Functional components Hard
A. Button click handlers are evaluated only when their visible text content changes
B. A memoized function component cannot safely receive event-handler props from its parent
C. The comparator ignores onSave, so React may retain a render containing an older callback
D. React automatically converts callback props into state captured during the initial mount