🌐
W3Schools
w3schools.com › react › react_es6_spread.asp
React ES6 Spread Operator
React Compiler React Quiz React Exercises React Syllabus React Study Plan React Server React Interview Prep React Bootcamp ... The JavaScript spread operator (...) copies all or part of an existing array or object into another array or object.
🌐
CoreUI
coreui.io › blog › draft-how-to-replace-all-occurrences-of-a-string-in-javascript
Mastering the Spread Operator (<code>...</code>) in React.js · CoreUI
September 3, 2023 - In this example, the spread syntax expands the numbers array into separate arguments for the calculateSum function. This technique is particularly useful when working with functions that accept a variable number of arguments.
Discussions

reactjs - React: how to use spread operator in a function that toggles states? - Stack Overflow
I made an example of my question here: EXAMPLE I'm mapping an array of objects that have a button that toggles on click, but when clicking on the button every object is changed. This is the code ex... More on stackoverflow.com
🌐 stackoverflow.com
What is the point of using the spread operator to pass props while also passing props individually?
...props contains all the properties that are not destructured from the object. It's called the rest operator. https://www.freecodecamp.org/news/javascript-rest-vs-spread-operators/ More on reddit.com
🌐 r/react
2
3
August 31, 2022
Need some help understanding the spread syntax
Hmm on my phone and didn’t open the link but I’ll try to explain (apologies if I glossed over something and misanswer) What I see is this: { ...grid[row][col], value: value } What this basically means is spread the result of grid[row][col] THEN set value to value. Meaning even if the grid part returned 5 if value is 4 its overwriting it. You see this a lot in redux. You spread the previous state onto a new object but in that new object you set some new values. Another example, switch the order of { value: value, ...grid[row][col], } And see what happens. Hopefully that helps Edit: spreading an object works how you thought it would but it dosent create a nested object. It just sets the key and value in the new object. Which then gets overwritten because you’re setting value in the same object More on reddit.com
🌐 r/reactjs
5
2
January 16, 2021
React Native Styling Dilemma: Array or Spread Operator for Best Performance and Readability?
The first is the way to go. That's what the styles array is made for. However, if bottom: 5 is static, I'll keep it on styles.container. I only create inline styles if is based in some computation: (e. g. bottom: someVariable) More on reddit.com
🌐 r/expo
6
8
June 18, 2023
🌐
Medium
medium.com › @truongtronghai › spread-operator-ba867a0e97b4
Spread operator. Some ways to use it in React Js | by Truong Trong Hai | Medium
October 3, 2024 - The spread operator can also be ... React. const original = { a: 1, b: 2 }; const copy = { ...original, c: 3 }; // { a: 1, b: 2, c: 3 } If you have multiple props to pass to a component, the spread operator can make your code cleaner. const user = { name: "Alice", age: 25, email: "alice@example.com" }; const UserProfile = ({ name, age, email }) => ( <div> <h2>{name}</h2> <p>Age: {age}</p> <p>Email: {email}</p> </div> ); // Using the ...
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › what-is-the-meaning-of-spread-operator-in-reactjs
What is the Meaning of Spread Operator (...) in Reactjs? - GeeksforGeeks
July 23, 2025 - Step 1: Create a React application ... command: ... Example: This example uses the spread operator to pass the person object's properties (name and age) as individual props to the Details component....
🌐
Medium
medium.com › @finnkumar6 › chapter-11-mastering-the-es6-spread-operator-in-react-with-examples-real-world-use-cases-3d0fb864c4e7
Chapter 11:🚀 Mastering the ES6 Spread Operator in React (With Examples & Real-World Use Cases) | by Aryan kumar | Medium
February 1, 2025 - After finishing this, you will be using … in your React projects as a pro. Now, grab a coffee ☕ and sit down, let us dive into it. So simply the spread operator (…) lets you take an array or object and spread them into a new array or object.
🌐
DEV Community
dev.to › edriso › using-the-spread-operator-in-react-426e
Using the Spread Operator in React - DEV Community
January 5, 2026 - This is equivalent to manually passing each prop like this: <UserProfile name={user.name} age={user.age} location={user.location} /> The spread operator can also be used to clone an object and update specific properties.
🌐
CoderCrafter
codercrafter.in › home › blog › master the react es6 spread operator: a complete guide with examples & best practices
Master the React ES6 Spread Operator: A Complete Guide with Examples & Best Practices | CoderCrafter
October 10, 2025 - This is a fancy word for a simple concept: don't change the original data. Instead, create a new, updated copy of the data. This allows React to efficiently detect changes and know when to re-render your components. The spread operator is the perfect tool for this job.
🌐
Medium
medium.com › @malkamalik007 › spread-operator-in-react-905a25a15a7a
Spread Operator (...) in React
September 22, 2024 - The spread operator makes this easier and cleaner. 1. Copying Arrays or Objects Using the Spread Operator · Let’s start with a simple example — copying arrays. Suppose you have an array, and you want to create an exact copy.
Find elsewhere
🌐
OneCompiler
onecompiler.com › javascript › 3yyj44jxk
functions & spread operator in react js - JavaScript - OneCompiler
//Object spread const post = { ...options, type: "new", } //array spread const users = [...adminUsers, ...normalUsers]
🌐
Scrimba
scrimba.com › articles › react-spread-operator
How to use the spread operator (...) in React
January 31, 2023 - Using the spread operator to combine two arrays into one · This can be useful when copying arrays or objects, or when working with a number of arguments or properties. In the context of React, the spread operator can be used to spread an object of props onto an element in a React component, making it easier to pass down props to child components but more on that later!
🌐
Stackademic
blog.stackademic.com › spread-operator-in-javascript-and-reactjs-a-quick-guide-8db6a19d5e37
Spread Operator in JavaScript and React: A Quick Guide | by Oluwaseun | Stackademic
October 17, 2023 - In the example, the spread operator is used to pass the user object’s properties (name, age, and gender) as individual props to the ChildComponent at once rather than passing the props one after the other. When updating a state in Reactjs, it is important to create a copy of the object or array we intend to update in order to preserve the original state or to make it immutable (unchanged).
🌐
DMC, Inc.
dmcinfo.com › latest-thinking › blog › id › 9668 › 5-great-uses-of-the-spread-operator-in-a-react-app
5 Great Uses of the Spread Operator in a React App | DMC, Inc.
December 30, 2025 - Probably the most common usage of the spread operator in a React app is in passing props down to a child component. So long as the object you’re spreading includes all the properties the child component requires, the child component will use ...
🌐
DhiWise
dhiwise.com › post › how-to-simplify-your-react-code-with-the-spread-operator
The Ultimate Guide To Using The React Spread Operator
October 31, 2023 - It can also be used to spread an array into separate elements, which can be particularly useful when working with lists in React. The spread operator can be used to pass multiple props to a component.
🌐
Medium
medium.com › @pojotorshemi › uses-of-spread-operator-in-javascript-react-f5f456186e63
Uses of Spread Operator in JavaScript, React. | by akpojotor shemi | Medium
July 27, 2020 - In react redux and reducer functions, spread operator are applied to compute new state without mutating state.
Top answer
1 of 2
2

Of course every object will change because you need to keep track of toggled state for each button. Here is one way to do it:

import { useState } from "react";
import "./styles.css";

const songs = [
  {
    name: "Song A",
    id: "s1"
  },
  {
    name: "Song B",
    id: "s2"
  },
  {
    name: "Song C",
    id: "s3"
  }
];

export default function App() {
  const [toggled, setToggled] = useState([]);

  const handleClick = (id) => {
    setToggled(
      toggled.indexOf(id) === -1
        ? [...toggled, id]
        : toggled.filter((x) => x !== id)
    );
  };
  return (
    <div className="App">
      <h1>SONGS</h1>
      <div className="container">
        {songs.map((song) => {
          return (
            <div className="song-container" key={song.id}>
              <h4>{song.name}</h4>
              {toggled.indexOf(song.id) === -1 ? (
                <button onClick={() => handleClick(song.id)}>PLAY</button>
              ) : (
                <button onClick={() => handleClick(song.id)}>STOP</button>
              )}
            </div>
          );
        })}
      </div>
    </div>
  );
}

There are many ways to do it. Here, if an id is in the array it means that button was toggled. You can also keep ids of toggled buttons in object for faster lookup.

2 of 2
1

One way of handling this requirement is to hold local data into states within the Component itself.

I have created a new Button Component and manages the toggling effect there only. I have lifted the state and handleClick method to Button component where it makes more sense.

const Button = () => {
  const [toggleButton, setToggleButton] = useState(true);
  const click = () => {
    setToggleButton((prevValue) => !prevValue);
  };

  return <button onClick={click}>{toggleButton ? "Play" : "Stop"}</button>;
};

Working Example - Codesandbox Link

🌐
Medium
medium.com › @fa22-bse-004 › how-to-use-the-spread-operator-in-react-eb6e071b57f4
How to use the spread operator (…) in React | by maryam hafeez | Medium
September 22, 2024 - A spread operator spreads a multiple array of objects providing it with the structure of a single array which can consists of further arrays or objects or any property, Like copying multiple arrays into one array as a separate array. However if we talk in reference to React, spread operator spreads an object of props onto an element in available in React component.
🌐
LinkedIn
linkedin.com › pulse › react-spread-operator-rogers-muyinda
React spread operator {...}
October 6, 2023 - For example: const person = { name: "Alice", age: 25, city: "New York" }; ... Here, name will be assigned the value "Alice", and otherInfo will contain { age: 25, city: "New York" }. The ... operator is a versatile tool that allows you to manipulate ...
🌐
IQCode
iqcode.com › code › javascript › spread-operator-react
spread operator react Code Example
October 28, 2021 - spread operator react spread elementt in array react spread operator in javascript and react reactjs rest operator spread operator in react component spread operator reacr how to use the spread operator in states react spread object into set state using spread operator in push array. react react native user spread to set array of objects spread operator and react state spread operator and react this spread operator react spread and rest syntax react native spread operator in react js how to use spread operator in react why we use spread operator in react react spread state react spread array s
🌐
Zhenyong
zhenyong.github.io › react › docs › jsx-spread.html
JSX Spread Attributes | React
The ... operator (or spread operator) is already supported for arrays in ES6. There is also an ECMAScript proposal for Object Rest and Spread Properties.