React Junior

1 / 16

What does it mean to lift state up, and what architectural problem does this solve?

Select the correct answer

1

Moving state into a global store so it is accessible from any component in the tree.

2

Moving shared state to the closest common ancestor so sibling components stay in sync.

3

Moving state into a ref so updates no longer trigger unnecessary re-renders of parents.

4

Moving local state into a child component so the parent re-renders less frequently overall.

What is prop drilling and what are the built-in React ways to solve it?

Select the correct answer

1

Passing props through many intermediate layers; solved only by adding Redux or another state library.

2

Re-rendering deep child trees too often; solved with useMemo and splitting into smaller components.

3

Passing props through many intermediate layers; solved with the Context API and component composition.

4

Mutating props inside children directly; solved by memoizing components with React.memo and useCallback.

What is prop drilling, and at what point does it become a problem?

Select the correct answer

1

Passing too many props to one component at once; it becomes a problem when render performance noticeably degrades

2

Passing props through many intermediate components that don't use them; it hurts maintainability at deep levels

3

Mutating props directly inside a child component; it becomes a problem once the parent re-renders and overwrites them

4

Reading props before they are defined on mount; it becomes a problem when undefined values break the first render

How does React handle one-way data flow, and why is this considered an advantage over two-way data binding?

Select the correct answer

1

Data flows in both directions automatically between parent and child, which keeps every component perfectly in sync

2

Data is stored globally and read by any component, so flow direction never matters and updates stay fully predictable

3

Data flows up via props while children mutate parent state directly, which removes the need for explicit callbacks

4

Data flows down via props while changes flow up via callbacks, making state updates predictable and easy to trace

Why should we use <Fragment> (or <>) instead of a <div> wrapper, and how does this impact the DOM tree and CSS selectors like flexbox?

Select the correct answer

1

Fragments add a hidden wrapper node that browsers ignore, so flexbox can still target it without breaking the layout

2

Fragments move children into a portal outside the tree, which avoids extra nodes but detaches them from flex parents

3

Fragments render a lightweight span node instead of a div, which keeps the DOM smaller while still scoping flex rules

4

Fragments group children without adding a DOM node, so layouts like flexbox apply directly to the real elements

What is the difference between State and Props in React?

Select the correct answer

1

State and props are both read-only, but only state can be shared down the tree to multiple nested child components

2

Props are private and mutable within a component, while state is read-only and passed in from a parent component

3

State is private and mutable within a component, while props are read-only and passed in from a parent

4

State and props are both mutable, but only props trigger a re-render when their underlying values actually change

What is JSX, and what does it actually compile to?

Select the correct answer

1

JSX compiles into HTML strings that React injects into the page directly

2

JSX is syntactic sugar compiled into React.createElement() calls returning objects

3

JSX is parsed natively by the browser into real DOM nodes during runtime

4

JSX is converted into template literals that React evaluates lazily later

Why must we always start Component names with a capital letter in JSX?

Select the correct answer

1

Capitalization tells the bundler to tree-shake unused components during builds

2

Lowercase names are treated as DOM tags while capitalized names map to components

3

Capital letters are required by the JavaScript class syntax used to define them

4

Lowercase names cause naming collisions with built-in React reserved keywords

What is the difference between a class component and a function component, and why has the community largely shifted to function components?

Select the correct answer

1

Function components cannot hold state, so they suit only presentational UI pieces

2

Class components are faster since they avoid recreating functions on every render

3

Class components support hooks too but require binding methods in the constructor

4

Function components use hooks for state and effects, making logic simpler to reuse

What are the different ways to conditionally render content in JSX, and what are the pitfalls of using short-circuit evaluation with values like 0?

Select the correct answer

1

Using && with 0 renders true since the expression short-circuits to a boolean

2

Using && with 0 renders nothing since React always skips falsy values silently

3

Using && with 0 renders the 0 itself because it is falsy but still a value

4

Using && with 0 throws an error because numbers cannot be rendered as JSX nodes

How does the children prop work, and how does it enable component composition?

Select the correct answer

1

The children prop is an array of sibling components rendered next to each other

2

The children prop holds references to child instances for direct method calls now

3

The content nested between a component's tags is passed as props.children to render

4

The children prop must be explicitly passed as an attribute named children always

How do the three forms of the useEffect dependency array (no array, empty array, populated array) differ in terms of when the effect runs?

Select the correct answer

1

No array runs once before mount; empty array runs after every render; populated array runs only when all values match.

2

No array runs only on unmount; empty array runs on every update; populated array runs once when any listed value resets.

3

No array runs after every paint; empty array runs twice on mount; populated array runs until its values stop changing.

4

No array runs after every render; empty array runs once after mount; populated array runs when listed values change.

What is the purpose of "Keys" in lists, and what happens if you use a random value or an index as a key?

Select the correct answer

1

Keys cache rendered items; random or index keys disable caching and force only full re-renders

2

Keys validate props; random or index keys skip validation and silently drop the invalid items

3

Keys identify items; random or index keys cause wrong reuse, state bugs, and slow updates

4

Keys sort list items; using an index sorts numerically while random values shuffle the order

What does useContext do, and how does a component subscribe to and re-render on context changes?

Select the correct answer

1

It registers an event listener on the provider and re-renders the component only when its own props change.

2

It reads a context's current value and re-renders the component whenever the nearest provider's value changes.

3

It creates a new context object and re-renders every component in the tree whenever any piece of state updates.

4

It memoizes the provider's value and re-renders only the children that are wrapped in React.memo.

What is the overall purpose of Strict Mode in React, and what does wrapping your app in it accomplish?

Select the correct answer

1

It optimizes rendering performance by skipping unnecessary updates automatically at runtime

2

It highlights potential problems in development by double-invoking certain functions

3

It enforces stricter type checking on props and state throughout production builds

4

It prevents unsafe lifecycle methods from running by blocking them entirely in production

Explain the difference between the Virtual DOM and the real DOM, and why is the Virtual DOM considered a performance optimization?

Select the correct answer

1

The Virtual DOM is a faster browser-native DOM that renders elements directly without any diffing at all.

2

The Virtual DOM stores components on the server and syncs them down to the real DOM over the network.

3

The Virtual DOM is a lightweight in-memory tree; React diffs it to batch and minimize costly real DOM updates.

4

The real DOM is a lightweight copy that React updates first before flushing it into the Virtual DOM.

React Junior Quiz | TechPrep