setState is async, and you need to invoke the function in the callback.

this.setState({
  languages: [...langs]
}, () => console.log(this.state.languages)
);
Answer from Stan Luo on Stack Overflow
🌐
W3Schools
w3schools.com › react › react_es6_spread.asp
React ES6 Spread Operator
Assign the first and second items from numbers to variables and put the rest in an array: const numbers = [1, 2, 3, 4, 5, 6]; const [one, two, ...rest] = numbers; ... const car = { brand: 'Ford', model: 'Mustang', color: 'red' } const car_more ...
Discussions

SetState in an array with React spread operator
This will spread all the previous values into a new object, plus the one you want to add. I personally always use the functional way of setting the state when the new one depends on a previous state value, but your way is fine here too. ... Sign up to request clarification or add additional context in comments. ... You should not use spread operator ... More on stackoverflow.com
🌐 stackoverflow.com
Spread array of objects to array of objects react
I am using redux with react and I am trying to append my array of objects gotten from my api to my redux state which is an array of objects This is my reducer... import { GET_BOOKS } from "../act... More on stackoverflow.com
🌐 stackoverflow.com
How do you update a value inside an array of objects with useState?
People already answered you here about how you use setState in your case. I would strongly suggest you to use useReducer instead of useState. It would allow you to have more complex operations tied to your state and thus, save you from writing too much code and increase readability. You could, for example, do this: dispatch({type: "update", obj: { id:3, newProperty: "hellowWorld" } }) or dispatch({type: "replace", obj: { id:3, ...properties }) Whenever your state gets too complex. Always consider using the useReducer hook . More on reddit.com
🌐 r/react
32
14
April 15, 2022
Can you spread an array of components in React?
In your case, JSX is transpiled to React.createElement via Babel. Here's the signature for createElement: function createElement

, T extends Element>( type: string, props?: ClassAttributes & P, ...children: ReactNode[]): DOMElement; Notice the children are variadic, and note that a child can be an array. In JSX, {...components} happens to transpile to...the same thing actually: {...components}. This is an object literal, and is not a valid child type. This works:

{components} More on reddit.com
🌐 r/javascript
6
2
January 3, 2018
🌐
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 - This method is particularly effective ... React state, the spread operator simplifies the process of creating a new array that includes updates or additions without mutating the existing array....
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Spread_syntax
Spread syntax (...) - JavaScript - MDN Web Docs - Mozilla
May 22, 2026 - The spread (...) syntax allows an iterable, such as an array or string, to be expanded in places where zero or more arguments (for function calls) or elements (for array literals) are expected. In an object literal, the spread syntax enumerates the properties of an object and adds the key-value ...
🌐
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 - Spread operator allows an iterable such as an array expression or string to be expanded in places where zero or more arguments (for function calls) or elements (for array literals) are expected, or an object expression to be expanded in places ...
🌐
Scrimba
scrimba.com › articles › react-spread-operator
How to use the spread operator (...) in React
January 31, 2023 - Using the spread operator to combine ... 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, ......
🌐
Medium
medium.com › @thejasonfile › using-the-spread-operator-in-react-setstate-c8a14fc51be1
Using the spread operator in React setState | by Jason Arnold | Medium
May 25, 2017 - That’s when I remembered the spread operator […]. The spread operator can be used to take an existing array and add another element to it while still preserving the original array (famous original array’s?).
Find elsewhere
🌐
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 provides a concise way to pass props, copy objects, and manage the state. It can also be used to spread an array into separate elements, which can be particularly useful when working with lists in React.
🌐
DEV Community
dev.to › edriso › using-the-spread-operator-in-react-426e
Using the Spread Operator in React - DEV Community
January 5, 2026 - In JavaScript, the spread operator (...) allows you to spread the properties of an object or elements of an array into individual items. In React, it's commonly used to pass all properties of an object as props to a 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 › krisperu › exploring-use-cases-for-map-filter-spread-in-react-118o
Exploring .map .filter ...spread in React - DEV Community
March 22, 2022 - ... The spread operator is a part of ES6 and is just used by React. It creates a copy of an existing array and "spreads" the elements, and adds them and any new elements and returns a new array.
🌐
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 - The Spread Operator ( ... ) in react is used to manage and manipulate props, arrays, and states. It is a JavaScript ES6 feature that allows to expand the arrays, objects, and any other iterable items.
🌐
Medium
medium.com › @malkamalik007 › spread-operator-in-react-905a25a15a7a
Spread Operator (...) in React
September 22, 2024 - The spread operator (…) is considered ... iterables. In React, the spread operator is used to ease the operations of passing props, handling state and manipulating component properties....
🌐
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 - However if we talk in reference to React, spread operator spreads an object of props onto an element in available in React component. ... A spread operator is denoted by three consecutive dots: … . ... If you want to work on multiple arrays ...
🌐
Medium
iainrobertzon.medium.com › spread-operator-basics-and-react-97a555fe2eee
Spread Operator Basics and React. When working within React class… | by Iain Robertson | Medium
February 7, 2021 - Here, we are using the spread operator to pessimistically add a new user object to our existing array of user objects held in state. The spread operator can also be used when passing an object into props in a react component.
🌐
Medium
medium.com › @muesingb › spread-operator-examples-using-arrays-and-objects-579af5581743
Spread Operator Examples using Arrays and Objects | by Muesingb | Medium
April 19, 2020 - With the spread operator, it instead creates a copy of what you’re referencing and allocates new memory for it. One case where it’s valuable to copy instead of directly mutating data is when using state in React. Note that copying only goes one level deep, it does not copy nested arrays and objects...
🌐
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 - If you’re trying to overwrite ... operator, or the existing property will overwrite your new value! The spread operator can also be used working with arrays, which can be very useful in a React application....
🌐
Physics Forums
physicsforums.com › other sciences › programming and computer science
Why use spread operator in this react program? What does it do? • Physics Forums
January 4, 2023 - The spread operator is actually a part of javascript ES6 not react.js However, the spread operator in React.js is used to spread an array of values or the properties of an object into a new array or object. It is represented by three dots (...).