StudyFox
कीमतेंब्लॉगएक्सटेंशनमुफ़्त टूल
  • कीमतें
  • ब्लॉग
  • एक्सटेंशन
  • मुफ़्त टूल
  • शुरू करेंसाइन इन
StudyFox

अपने नोट्स, PDF और स्लाइड्स को फ़्लैशकार्ड, क्विज़, नोट्स और माइंड मैप में बदलें।

StudyFox खोलें

स्टडी टूल्स

  • होमवर्क हेल्पर
  • नोट मेकर
  • फ़्लैशकार्ड मेकर
  • क्विज़ मेकर
  • माइंड मैप मेकर

प्रोडक्ट

  • कीमतें
  • Chrome एक्सटेंशन
  • मुफ़्त एक्सटेंशन
  • स्टडी सेट देखें
  • ब्लॉग

सहायता

  • सहायता केंद्र
  • संपर्क करें
  • गोपनीयता नीति
  • सेवा की शर्तें

तुलना करें

  • Chegg का विकल्प
  • Course Hero का विकल्प
  • Coursology का विकल्प
  • Photomath का विकल्प
  • Gauthmath का विकल्प
  • PhotoSolve का विकल्प
  • CollegeTools का विकल्प
  • Transcript का विकल्प
  • SmartSolve का विकल्प
  • Homeworkify का विकल्प
  • AnswersAi का विकल्प
  • StudyX का विकल्प
  • Quizlet का विकल्प
  • Anki का विकल्प
  • Knowt का विकल्प
  • Brainscape का विकल्प
  • सभी तुलनाएँ

© 2026 StudyFox AI. सर्वाधिकार सुरक्षित।

  • X
  • Discord
  • Instagram
ExploreEngineering & TechWeb DevelopmentReact Fundamentals Quiz: JSX, Props, State & Rendering

Quiz · Medium

React Fundamentals Quiz: JSX, Props, State & Rendering

Twenty-two questions on JSX rules, props and one-way data flow, state snapshots and immutable updates, keys, conditional rendering and the render cycle, with diagram questions.

by Kill h.22 questionsCreated Nov 20, 2026, 08:26 PM
Web Development· ReactTags#react#jsx#state#props

22 questions

  1. 1

    What does JSX compile to?

    • A

      CSS-in-JS objects

    • B

      HTML strings that are inserted with innerHTML

    • C

      A separate template language that React parses at runtime

    • Plain JavaScript function calls that create React elements

    A compiler (Babel, SWC, TypeScript) turns JSX into calls like jsx('div', { children: ... }). These return plain objects (elements) that describe the UI; React turns them into DOM updates. It is neither a string template nor HTML.

  2. 2

    Which JSX is correct for adding a CSS class and an inline red color to a div?

    • A

      <div className="box" style={color: "red"}>

    • B

      <div class="box" style="color: red">

    • C

      <div class=box style={{ color: red }}>

    • <div className="box" style={{ color: "red" }}>

    JSX uses className, and style takes a JavaScript object, hence the double braces (outer braces for the JS expression, inner braces for the object literal). A style string and class are HTML, and {color: "red"} with one pair of braces is a syntax error.

  3. 3

    Why must a custom component be named <Card /> and not <card />?

    • A

      React only supports PascalCase for performance

    • Lowercase tags are treated as built-in DOM elements; capitalized names are looked up as components

    • C

      Lowercase names are reserved for class components

    • D

      Lowercase tags are removed by the compiler

    JSX decides what to render by the first letter: div becomes the string 'div' (a DOM element), Card becomes a reference to your function or class named Card.

  4. 4

    In the diagram, how does the AddTodoForm component make the App component add a todo?

    • It calls a function passed down as a prop (onAdd), and App updates its own state

    • B

      It sends the data up through context only

    • C

      It re-renders App by calling App() itself

    • D

      It directly modifies App's state

    React has one-way data flow: parents pass data down as props, children never write to the parent's state. To ask for a change, the parent passes a callback prop, the child calls it, and the parent calls its own setState, which re-renders the tree.

  5. 5

    A component declares const [count, setCount] = useState(0). A click handler runs setCount(count + 1) three times in a row. What is count after the re-render?

    • A

      It throws an error

    • B

      0

    • 1

    • D

      3

    Each call uses the same snapshot value count = 0, so all three queue setCount(1). To increase by 3, use updater functions: setCount(c => c + 1) three times.

  6. 6

    Which statement correctly adds an item to an array held in state?

    • setItems([...items, newItem])

    • B

      items[items.length] = newItem; setItems(items)

    • C

      items.push(newItem)

    • D

      setItems(items.push(newItem))

    State must be treated as immutable: create a new array. push mutates the existing array (and returns a number, so the last option would set state to a number). Calling setItems(items) with the same reference does not re-render.

  7. 7

    A component renders {items.length && <List items={items} />} with items = []. What appears on the screen?

    • A

      The text "false"

    • The number 0

    • C

      An empty list

    • D

      Nothing

    0 && x evaluates to 0, and React renders numbers (0 included). Only null, undefined, true and false render nothing. Use items.length > 0 && ... or a ternary.

  8. 8

    What is wrong with <button onClick={deleteItem(id)}>Delete</button>?

    • A

      onClick must be lowercase

    • B

      Nothing, this is the standard way

    • deleteItem(id) runs during render; it should be wrapped: onClick={() => deleteItem(id)}

    • D

      id cannot be passed to event handlers

    The expression inside the braces is evaluated while rendering, so the function is called immediately and its return value (often undefined) becomes the handler. Pass a function, not a function call.

  9. 9

    What is the best key for items in a list of todos loaded from a database?

    • A

      Math.random()

    • The unique id of each todo

    • C

      The todo text

    • D

      The array index

    Keys must be stable and unique among siblings. Ids keep identity when the list is reordered or filtered. Indexes break state when items move, random keys change on every render (remounting everything), and text can repeat or be edited.

  10. 10

    Looking at this diagram, what does React do after comparing the old and new virtual DOM trees?

    • A

      It updates all three li elements to be safe

    • B

      It reloads the page

    • It updates only the changed part of the real DOM (removes the class attribute on the first li)

    • D

      It replaces the entire ul in the real DOM

    Reconciliation finds the minimal difference (here the className prop went from 'selected' to null) and applies just that change in the commit phase.

    Image: Moderateasneeded, CC BY-SA 4.0, via Wikimedia Commons.

  11. 11

    In the render cycle diagram, which step may update the real DOM?

    • A

      Cleanup

    • Commit

    • C

      Trigger

    • D

      Render

    Rendering only calls your components to compute the next UI (it must be pure). In the commit phase React applies the changes to the DOM. Effects then run after the browser paints.

  12. 12

    Which of these makes a component re-render?

    • A

      A ref.current value changes

    • B

      console.log is called inside it

    • Its state changes

    • D

      A local let variable inside it changes

    State updates (and parent re-renders or context changes) trigger renders. Local variables are recreated each render and refs are mutable boxes that React does not watch.

  13. 13

    What is a controlled input?

    • A

      An input with the disabled attribute

    • B

      An input that React validates automatically

    • An input whose value comes from React state, updated via onChange

    • D

      An input rendered only by the server

    <input value={text} onChange={e => setText(e.target.value)} />: React state is the source of truth. An uncontrolled input keeps its own value in the DOM.

  14. 14

    Which one is not allowed by the Rules of Hooks?

    • A

      Calling useState at the top of a function component

    • B

      Calling useEffect at the top of a custom hook

    • C

      Calling a custom hook at the top level of a component

    • Calling useState inside an if block

    Hooks must run in the same order on every render, so they cannot be put in conditions, loops or nested functions. You can put the condition inside the hook's callback instead.

  15. 15

    True or False: a component may change its own props (for example props.title = 'New').

    • False

    • B

      True

    Props are read-only. A component should treat them as immutable inputs; if something needs to change, it belongs in state, or the parent must pass new props.

  16. 16

    What is the purpose of the children prop?

    • A

      It holds the state of child components

    • B

      It is the array of keys of rendered elements

    • C

      It lists the component's child functions

    • It contains whatever JSX is nested between a component's opening and closing tags

    For <Card><p>Hi</p></Card>, Card receives props.children equal to the <p> element. This makes wrappers and layouts easy.

  17. 17

    What does <>...</> do in JSX?

    • A

      Marks a component as a client component

    • Groups children into one parent without adding an extra DOM element

    • C

      Comments out the code between

    • D

      Creates a portal

    It is shorthand for <React.Fragment>. Returning a Fragment lets a component return several siblings without an extra wrapper div.

  18. 18

    Why do two sibling components that both need the same changing value usually get that state from their parent?

    • A

      State is shared automatically between siblings

    • B

      Sibling components cannot render at the same time

    • Lifting state up keeps one source of truth that both read through props

    • D

      React forbids components from having state

    If each sibling kept its own copy, they would get out of sync. The common parent owns the state and passes it down (plus setters or callbacks).

  19. 19

    An <input> inside a UserForm keeps stale text when you switch from user A to user B. Which fix is idiomatic?

    • A

      Wrap the form in React.memo

    • B

      Use Math.random() as a key on every render

    • <UserForm key={user.id} user={user} />

    • D

      Call window.location.reload()

    A different key makes React unmount the old instance and mount a fresh one, resetting its state. A random key would reset on every render, and reloading the page throws away everything.

  20. 20

    Which behavior does React.StrictMode have in development?

    • A

      It disables hooks inside loops at runtime

    • It renders components (and runs effects) an extra time to expose impure code and missing cleanups

    • C

      It blocks network requests made during render

    • D

      It makes the production build smaller

    StrictMode is a development-only checker. It double-invokes render functions and, for effects, runs mount, unmount, mount again, so bugs from impure render or missing cleanup show up early. It does not change production.

  21. 21

    What is the correct way to update one field of an object in state?

    • A

      setUser(user.name = 'Ana')

    • setUser({ ...user, name: 'Ana' })

    • C

      setUser(user) after changing user.name

    • D

      user.name = 'Ana'

    Create a new object that copies the old fields and overrides one (spread, then the changed key). Mutating and re-setting the same object reference does not reliably trigger a re-render.

  22. 22

    What does createPortal(<Modal />, document.body) do?

    • A

      Creates a new React root with separate state

    • B

      Renders the modal on the server

    • C

      Copies the modal to every page

    • Renders the modal into document.body while it stays in the same place in the React tree

    Portals render children into a different DOM node (useful for modals and tooltips that must escape overflow or z-index) but context and event bubbling still follow the React tree.