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. An HTML file loaded directly by the browser
B. A CSS file that defines component styles
C. A JavaScript function that returns React elements
D. A database function that stores application data

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

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

3 What are props primarily used for in React?

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

4 How do props help make a component reusable?

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

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

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

6 What does component composition mean in React?

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

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

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

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

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

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

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

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 replacing the application's HTML document
B. By calling a callback received through props
C. By directly changing the parent's local variable
D. By editing the parent's JSX source file

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

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

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

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

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

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

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

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

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

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

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

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

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

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

19 Why should a form input have an associated label?

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

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

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

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 data={window.currentProduct} />
C. <ProductCard productId="42" selected="true" />
D. <ProductCard onClick={handleSelect(product)} />

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. Import every possible child component
C. Read the content from a global variable
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 value and onChange props
B. Keep the value only in internal state
C. Accept defaultValue and ignore later updates
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. items.length || <List items={items} />
B. items.length > 0 && <List items={items} />
C. Boolean(items) && <List items={items} />
D. items.length >= 0 && <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. Inside SearchBox only
B. Inside ProductList only
C. In each sibling independently
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 every task into one custom hook
B. Move all behavior into event handlers
C. Split data logic and focused UI components
D. Duplicate the component for each route

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

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

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. p-4 gap-2
B. mx-4 my-2
C. px-4 py-2
D. pl-4 pt-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. Build every utility name at runtime
C. Add the color through an element ID
D. Map variants to complete class strings

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-full md:w-1/2 lg:w-1/3
B. w-1/3 md:w-1/2 lg:w-full
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. Generate arbitrary class names from user input
C. Place all variants in global element selectors
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>Email address</label><input id="email" />
C. <label htmlFor="email">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. <div onClick={submit}>Search</div>
B. <a onClick={submit}>Search</a>
C. <button type="submit">Search</button>
D. <span role="link">Search</span>

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. Compute price * quantity during rendering
B. Set state on every component rendering
C. Store the product in unrelated global state
D. Copy both props into separate local states

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(name = 'Guest') { ... }
B. function Avatar({ name }) { name ||= props; }
C. function Avatar(props = name: 'Guest') { ... }
D. function Avatar({ name = 'Guest' }) { ... }

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. Keep one shared temperature in their parent
B. Read both values from the DOM after rendering
C. Update one input only when the form submits
D. Give each input unrelated temperature state

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. <div aria-label="Close"><svg aria-hidden="true" /></div>
B. <button role="img"><svg aria-label="Close" /></button>
C. <button><svg title="Close" /></button>
D. <button aria-label="Close"><svg aria-hidden="true" /></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(count + 2); setCount(count); };
B. const incrementTwice = () => { setCount(count + 1); setCount(count + 1); };
C. const incrementTwice = () => { setCount(c => c + 1); setCount(c => c + 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.map(item => ({ ...item, key: Math.random() }))} />
B. <DataList items={items} keyField="uuid" rowType="Row" nameField="title" />
C. <DataList items={items} renderItem={(item, index) => <Row key={index} item={item} />} />
D. <DataList items={items} getKey={item => item.uuid} renderItem={item => <Row item={item} />} />

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 titleText="Delete" bodyText="Confirm" buttonText="Remove" />
B. <Dialog header={<Title />} footer={<Actions />}> <Content /> </Dialog>
C. <Dialog data={record} type="delete" showCancel={true} showIcon={true} />
D. <Dialog renderMode="record" recordId={record.id} actionName="remove" />

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 shared component containing fixed disclosure HTML and CSS
B. A utility function that calls React hooks outside a component
C. A module-level singleton storing the currently open disclosure
D. A custom hook returning state, actions, and prop-getter functions

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. The raw input string and the scale of the most recently edited input
B. Independent Celsius and Fahrenheit numbers updated by separate handlers
C. Both raw strings plus effects that continuously synchronize each other
D. Only a parsed Celsius number recalculated after every individual keystroke

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 page renders every row detail directly and avoids list or row components entirely
B. The list reads global credentials and discovers retry endpoints from each rendered row
C. Each row owns authentication, cache invalidation, fetching, and its visual presentation
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[variant]}}
B. className={${styles.root} 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. Map each supported color to a complete literal class such as bg-red-600
B. Store only the numeric shade in state and interpolate the color statically
C. Move the interpolated class expression into a separate JavaScript utility file
D. Prefix the dynamic expression with tailwind: before assigning className

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. Replace every utility with one global .button rule containing all possible declarations
B. Create a Button component with static utility strings selected by typed variant props
C. Copy the existing utility list and document that callers must keep variants synchronized
D. Allow each caller to construct utility names dynamically from color and size strings

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. From md to below lg, and again at xl and above
B. Below md, and from lg to below xl only
C. Only from lg to below xl because hidden resets at lg
D. From md upward because the first responsive display rule wins

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. Add !important to every utility in the component's default class collection
B. Sort all class tokens alphabetically before assigning the resulting class string
C. Reverse the arguments to clsx so caller classes always control the cascade
D. Merge the result with a Tailwind-aware conflict resolver such as twMerge

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. <span id="email">Email</span><input aria-label="email-error" /><p role="status">Invalid email</p>
B. <label htmlFor="email">Email</label><input id="email" aria-invalid="true" aria-describedby="email-error" /><p id="email-error" role="alert">Invalid email</p>
C. <label>Email</label><input name="email" invalid="true" /><p className="error">Invalid email</p>
D. <label htmlFor="email-error">Email</label><input id="email" /><p aria-invalid="true">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 the card as a <div onClick> and stop propagation from a nested clickable <span>
B. Render one outer <button> for navigation and place a second Save <button> inside it
C. Wrap the entire <article> and its nested Save <button> inside a single <a> element
D. Use an <article> with a heading link expanded by CSS and a sibling <button> layered above it

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 framed ? <section><Editor key="a" /></section> : <Editor key="a" />;
C. return <section className={framed ? "frame" : undefined}><Editor /></section>;
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 record={record} reset={record !== record} />
B. <RecordForm key="record" record={{ ...record }} />
C. <RecordForm key={record.id} 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 ID, deriving the current product from the latest array
B. A copied selected product in each child, synchronized through separate effects
C. The selected array index, recalculated only when a child changes its selection
D. The selected product object, preserving its original reference across all fetches

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. Store the viewport width in a module variable shared by all rendered component instances
B. Initialize desktop markup on the server and replace it with mobile markup after hydration
C. Render one structure and express the layout change with CSS media queries
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. Give every tab tabIndex="0", use Tab for navigation, and place state in aria-checked
B. Use aria-expanded on every tab, Escape for movement, and links to unnamed tab panels
C. Keep tabs unfocusable, handle mouse clicks only, and announce selection through title
D. Use roving tabIndex, arrow-key navigation, aria-selected, and aria-controls references

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