What are these three dots in React doing?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In React code, the three dots syntax, written as ..., is just JavaScript. Depending on where it appears, it means either spread or rest, and React uses it constantly because it makes state updates, prop forwarding, and destructuring much shorter and clearer.
Spread in Objects
Object spread copies properties from one object into another.
The result is a new object containing all previous properties, with role overridden. In React, this is extremely common for immutable state updates.
That pattern keeps all existing fields while replacing only one property.
Spread in Arrays
Array spread copies elements into a new array.
In React, this is a standard way to update list state without mutating the old array.
You can also merge arrays this way:
Spread in JSX Props
One of the most recognizable React uses is prop spreading.
This forwards every property from props to the actual DOM element. It is useful for wrapper components that want to preserve standard DOM behavior.
A more realistic example is:
Here children is handled explicitly and the remaining props are passed through.
Rest in Destructuring
When ... appears on the left side of destructuring, it means rest. It gathers the remaining values into one object or array.
title and subtitle are pulled out, while rest contains everything else.
The same idea works in function parameters:
Here rest collects many arguments into an array.
Spread vs Rest
A simple way to remember the difference is:
- spread expands outward
- rest gathers inward
Examples:
- object literal or array literal: usually spread
- JSX prop block: spread
- function arguments collected into one variable: rest
- destructuring “the rest of the props”: rest
The syntax is identical, but the direction of data flow tells you which meaning applies.
Why React Uses It So Often
React encourages:
- immutable state updates
- reusable wrapper components
- explicit prop destructuring
Spread and rest fit those patterns naturally. They reduce boilerplate and make intent visible.
For example, updating nested state or forwarding props without ... would require much more repetitive code. That is why you see the syntax so often in component code.
Shallow Copy Warning
The most important caveat is that spread is shallow. If an object contains nested objects, the nested values are still shared unless you copy those levels too.
nextState.user still points to the same nested object as state.user. That surprises many developers the first time they update nested state.
Common Pitfalls
- Forgetting that spread only makes a shallow copy, not a deep clone of nested data.
- Spreading props blindly into DOM elements and unintentionally passing invalid or unwanted attributes.
- Misreading rest syntax as spread when it appears on the left side of destructuring.
- Putting prop spreads in the wrong order, which changes which values win when keys conflict.
- Using spread everywhere by habit instead of deciding whether a more explicit prop API would be clearer.
Summary
- In React,
...is normal JavaScript syntax used as either spread or rest. - Spread copies or expands object properties, array elements, and JSX props.
- Rest gathers remaining props or function arguments into one value.
- React uses it heavily for immutable state updates and prop forwarding.
- The biggest caveat is that spread is shallow, so nested objects still need special care.

