🌍 ReactJS · subject

ReactJS React Components Syllabus

The React Components syllabus for ReactJS in full: 3 chapters and 9 topics, every one listed below, plus 50 React Components flashcards with answers.

3Chapters
9Topics
50Flashcards

React Components syllabus: all 3 chapters

Expand any chapter to see its topics and sub-topics.

  1. Functional Components

    3 topics
    • Creating Functional Components
    • Props in Functional Components
    • State in Functional Components
  2. Class Components

    3 topics
    • Creating Class Components
    • Lifecycle Methods
    • State and Props in Class Components
  3. Component Communication

    3 topics
    • Parent to Child
    • Child to Parent
    • Sibling to Sibling

ReactJS React Components flashcards — 50 questions with answers

  1. What is a functional component in React?

    A JavaScript function that accepts a single props object as an argument and returns React elements (JSX) describing what should appear on the screen.

  2. Write the minimal syntax for a functional component named Greeting that renders "Hello".

    function Greeting() { return <h1>Hello</h1>; } — or as an arrow function: const Greeting = () => <h1>Hello</h1>;

  3. What naming rule must every React component (functional or class) follow, and why?

    Its name must start with a capital letter. React treats lowercase names as built-in DOM tags (e.g. <div>) and capitalized names as user-defined components.

  4. Can a functional component return multiple sibling elements without a wrapping tag?

    Yes, by wrapping them in a Fragment: <>...</> or <React.Fragment>...</React.Fragment>, which groups children without adding an extra DOM node.

  5. Before React 16.8 (Hooks), what was the key limitation of functional components?

    They were stateless: they could not hold local state or use lifecycle methods, so they were used only as simple presentational ("dumb") components.

  6. What must a functional component return to render nothing at all?

    null (or false). Returning null tells React to render nothing for that component.

  7. What are props in React?

    Props (properties) are read-only inputs passed from a parent to a child component as attributes, allowing the parent to configure and pass data to the child.

  8. How do you access props inside a functional component?

    Through the function's first parameter, e.g. function Card(props) { return <p>{props.title}</p>; }, or by destructuring: function Card({ title }) {...}.

  9. Are props mutable or immutable inside the receiving component?

    Immutable (read-only). A component must never modify its own props; it must treat them as read-only to keep behavior predictable.

  10. How do you provide a default value for a missing prop in a functional component?

    Use default parameter values when destructuring, e.g. function Btn({ label = "Click" }) {...}, or set Btn.defaultProps = { label: "Click" }.

  11. What is props.children and how is it populated?

    props.children holds whatever JSX is nested between a component's opening and closing tags, e.g. <Box>Hello</Box> makes props.children equal to "Hello".

  12. How do you pass a function as a prop, and why is it commonly done?

    Pass it like any value: <Child onSave={handleSave} />. It lets a parent give the child a callback, commonly used so the child can send data back up (child-to-parent communication).

  13. Which Hook adds local state to a functional component?

    The useState Hook, imported from React: const [state, setState] = useState(initialValue);

  14. What does useState return?

    An array of exactly two elements: the current state value and a setter function to update it. It is typically destructured, e.g. const [count, setCount] = useState(0).

  15. When does the useState initializer argument actually run?

    Only on the component's first render (initial mount). On subsequent re-renders the argument is ignored and the current state is used.

  16. Why should you use the functional updater form setCount(prev => prev + 1) instead of setCount(count + 1)?

    Because state updates may be batched/asynchronous; the functional form always receives the latest state, avoiding stale-value bugs when multiple updates happen together.

  17. Does calling a useState setter mutate the current state variable immediately within the same render?

    No. The setter schedules a re-render; the state variable in the current render keeps its old value. The updated value is available on the next render.

  18. Two rules govern where Hooks like useState may be called. What are they?

    1) Only call Hooks at the top level (never inside loops, conditions, or nested functions). 2) Only call Hooks from React function components or custom Hooks.

  19. How do you correctly update a single field of an object stored in state with useState?

    Create a new object copying the old one and overriding the field: setUser(prev => ({ ...prev, name: "Al" })); never mutate the existing object directly.

  20. What is a class component in React?

    An ES6 class that extends React.Component (or React.PureComponent) and implements a render() method returning JSX.

Show the other 30 React Components flashcards
  1. Write the minimal syntax for a class component named Hello that renders "Hi".

    class Hello extends React.Component { render() { return <h1>Hi</h1>; } }

  2. Which method is mandatory in every class component?

    The render() method — it is the only required method and must return the JSX (or null) to display.

  3. How is state initialized in a class component?

    In the constructor: constructor(props){ super(props); this.state = { count: 0 }; } — or as a class field: state = { count: 0 };

  4. Why must super(props) be called in a class component constructor?

    It invokes the parent React.Component constructor and makes this.props available; omitting it leaves this.props undefined in the constructor.

  5. How do you access props and state inside a class component's render method?

    Via this.props (e.g. this.props.title) and this.state (e.g. this.state.count).

  6. What are the three phases of a class component's lifecycle?

    Mounting (being inserted into the DOM), Updating (re-rendering due to prop/state changes), and Unmounting (being removed from the DOM).

  7. Which lifecycle method runs once after a class component is first inserted into the DOM, and what is it used for?

    componentDidMount() — ideal for side effects like data fetching, subscriptions, or manual DOM/timer setup after the initial render.

  8. Which lifecycle method runs after every update (re-render) but not on the initial mount?

    componentDidUpdate(prevProps, prevState) — used to react to prop/state changes, e.g. refetch data when a prop changes.

  9. Which lifecycle method runs just before a component is removed, and what belongs there?

    componentWillUnmount() — used for cleanup: clearing timers, cancelling network requests, and removing event listeners/subscriptions to prevent memory leaks.

  10. What is the purpose of shouldComponentUpdate(nextProps, nextState)?

    A performance optimization: return false to skip re-rendering when the new props/state don't require an update; default behavior returns true.

  11. In componentDidUpdate, how do you avoid an infinite update loop when calling setState?

    Wrap the setState in a condition comparing prevProps/prevState to the current values, e.g. if (prevProps.id !== this.props.id) { ...setState... }.

  12. Which useEffect call approximates componentDidMount + componentWillUnmount?

    useEffect(() => { /* setup */ return () => { /* cleanup */ }; }, []) — the empty dependency array runs setup once on mount and the returned function on unmount.

  13. How must you update state in a class component, and why not assign this.state directly?

    Use this.setState({ ... }). Directly assigning this.state does not trigger a re-render and bypasses React's update mechanism.

  14. Is this.setState synchronous or asynchronous, and how do you read updated state right after calling it?

    It is asynchronous/batched. To read the result, use the second callback argument: this.setState({...}, () => { /* use this.state here */ }).

  15. How do you update state based on the previous state in a class component?

    Pass a function to setState: this.setState(prev => ({ count: prev.count + 1 })), ensuring the update uses the latest state rather than a possibly stale this.state.

  16. Can a class component modify this.props?

    No. Props are read-only in class components just as in functional components; only the parent that owns the data may change them.

  17. How do you correctly bind an event-handler method to this in a class component?

    Bind in the constructor (this.handle = this.handle.bind(this)), or define it as an arrow-function class field (handle = () => {...}) so this refers to the instance.

  18. Compare state and props in one sentence each.

    Props are read-only data passed in from a parent and owned externally; state is internal, mutable data owned and managed by the component itself.

  19. What is the standard direction of data flow in React?

    Unidirectional (one-way): data flows down from parent to child via props; there is no automatic upward or sibling flow.

  20. How does a parent pass data to a child component?

    By supplying it as a JSX attribute (prop) on the child element, e.g. <Child name="Al" count={5} />, which the child reads via props.

  21. When a parent's state changes and it is passed as a prop to a child, what happens to the child?

    The child re-renders with the new prop value, since React re-renders children when the props they receive change.

  22. Can a child directly change a value it received as a prop from its parent?

    No. Props are read-only; the child cannot mutate them. To change the data, the parent must update its own state (often via a callback the child calls).

  23. What is "prop drilling" in parent-to-child communication?

    Passing a prop down through several intermediate components that don't use it, just to reach a deeply nested child. It can be avoided with the Context API.

  24. How does a child send data up to its parent?

    The parent passes a callback function as a prop; the child invokes that function with data as an argument, e.g. props.onChange(newValue), letting the parent handle it.

  25. Give the code pattern for child-to-parent communication via a callback.

    Parent: <Child onSend={(val) => this.setState({ data: val })} />. Child: <button onClick={() => props.onSend('hi')}>Send</button>.

  26. Why can't a child mutate the parent's state directly?

    Because state is encapsulated in the parent; React enforces one-way data flow. The child must request a change by calling a parent-provided callback, and the parent updates its own state.

  27. What is "lifting state up" and when do you do it?

    Moving shared state to the closest common ancestor of the components that need it. You do it so multiple children can read/update the same data through props and callbacks.

  28. How do two sibling components share data in React?

    By lifting the shared state up to their common parent; the parent passes the state down to one sibling as a prop and passes an updater callback to the other, so changes propagate through the parent.

  29. Why can't sibling components communicate directly with each other?

    Because React's data flow is unidirectional (top-down) and siblings have no parent-child relationship; data must travel up to a common ancestor and back down through props.

  30. Name a built-in React feature that lets distant or sibling components share data without prop drilling.

    The Context API (React.createContext with a Provider and useContext/Consumer), which lets components read shared values without passing props through every level.

ReactJS React Components FAQ

What is in the ReactJS React Components syllabus?

ReactJS React Components is split into 3 chapters: Functional Components, Class Components and Component Communication. Together they contain 9 topics.

How many chapters are in ReactJS React Components?

3 chapters, containing 9 topics. The largest chapter is Functional Components, with 3 topics.

Are there flashcards for ReactJS React Components?

Yes — a 50-card React Components deck, printed in full in the flashcards section of this page and available in the Examius app with spaced repetition. The free plan covers one exam of your choice, including its flashcards; Examius Pro, a one-time purchase, unlocks every other exam and deck.