Question Bank
/

React Stateful vs Stateless Components: Two Explanations Quiz

React Stateful vs Stateless Components: Two Explanations Quiz

Two explanations of the stateful/stateless (smart vs presentational) split, plus companions on hooks-era state in function components and on testability trade-offs.

Question Bank
Easy
JavaScript
4 questions
quiz
react
interview-prep
fundamentals

929 views

22

Define a stateful (smart) component and a stateless (presentational) component, and explain why this split is a useful design boundary even in a hooks-only codebase.

Examples

Example 1:

Input: a component that owns a counter value and renders the count plus +/- buttons
Output: stateful (smart): it owns state and behavior.
Explanation: this component holds the counter in useState and decides how the user interactions mutate it.

Example 2:

Input: a component that takes `count` and `onIncrement` as props and renders them
Output: stateless (presentational): no state, no behavior of its own, easy to reuse.
Explanation: it is a pure function of its props; render-only.
import { useState } from 'react';

// presentational: pure function of props
function CounterView({ count, onInc, onDec }) {
    return (
        <div>
            <button onClick={onDec}>-</button>
            <span>{count}</span>
            <button onClick={onInc}>+</button>
        </div>
    );
}

// smart: owns state, plugs into the presentational piece
function Counter() {
    const [count, setCount] = useState(0);
    return (
        <CounterView
            count={count}
            onInc={() => setCount((c) => c + 1)}
            onDec={() => setCount((c) => c - 1)}
        />
    );
}