Error you are getting because of the this key:

loginForm.email

It's not a valid object key.

Write it like this:

return { 
    ...state, 
    loginForm: {
        ...state.loginForm,
        email: action.payload.email
    } 
}
Answer from Mayank Shukla on Stack Overflow
🌐
DEV Community
dev.to › mlgvla › javascript-using-the-spread-operator-with-nested-objects-2e7l
JavaScript: Using the spread operator with nested objects - DEV Community
February 14, 2022 - Ok, we did pretty well with not changing the top-level elements, but unfortunately, the nested objects at level 2 and 3 WERE changed. ... The spread operator only creates a new address location for the top-level elements.
Discussions

How to avoid overwriting nested object with spread operator?
You'd have to spread at every level. const added = { ...shared, a: { ...shared.a, c: 2, }, }; More on reddit.com
🌐 r/learnjavascript
9
18
July 2, 2020
arrays - How to spread a nested object in Javascript? - Stack Overflow
I've been trying to copy a nested object properties into another object by using the spread operator. But, I got an error. So I tried to spread the nested object separately: try { console.log( ... More on stackoverflow.com
🌐 stackoverflow.com
May 29, 2020
Using Spread operator to update the state in react
Hi, does copying nested object using spread have different address (reference). We do that so react can know while rendering the dom that there is some change (because of the references are different). But the value we update remains the same since spread doesn’t work with nested keys? More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
1
0
February 20, 2020
does redux toolkit really make nested object property updates as easy as this?
Yes, you can do that. More on reddit.com
🌐 r/reduxjs
6
6
September 16, 2022
🌐
Tania's Website
taniarascia.com › understanding destructuring, rest parameters, and spread syntax
Understanding Destructuring, Rest Parameters, and Spread Syntax | Tania Rascia's Website
May 14, 2020 - Spread allows you to make a shallow copy of an array or object, meaning that any top level properties will be cloned, but nested objects will still be passed by reference.
🌐
Reddit
reddit.com › r/learnjavascript › how to avoid overwriting nested object with spread operator?
r/learnjavascript on Reddit: How to avoid overwriting nested object with spread operator?
July 2, 2020 -

b is overwritten:

const shared = { a : { b : 1 } }
const added = { ...shared, a : { c : 2 } }

console.log(added);

Actual use case is below. I was testing the above in JSBin because I thought this might be a concern.

How can I avoid overwriting b (or voice in my real example)? I want to set the ssmlGender in shared options, but not the languageCode.

I'm thinking I might have to set properties one by one using dot or bracket notation? Or is there a more concise way?

      const sharedOptions = {
         , voice : { languageCode : "", ssmlGender : voiceGender.male }
         , audioConfig : {audioEncoding : "OGG_OPUS"}
      }

      const foreignAudioOptions = {
         ...sharedOptions
         , input : {text : ""}
      }

      const englishAudioOptions = {
         ...sharedOptions
         , input : {text : ""}
      }
Find elsewhere
🌐
DEV Community
dev.to › krsgrnt › safely-copying-nested-objects-in-javascript-5fpi
Safely copying nested objects in JavaScript - DEV Community
May 16, 2019 - Shallow in this context means that for any given object that is spread, the uppermost level of the new variable is an object containing the same properties and values of the original object, but at a new reference in memory. Any lower level or nested objects, however, will remain pointing to ...
🌐
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 - All primitives can be spread in objects. Only strings have enumerable own properties, and spreading anything else doesn't create properties on the new object. ... When using spread syntax for function calls, be aware of the possibility of exceeding the JavaScript engine's argument length limit.
🌐
Educative
educative.io › answers › what-is-the-spread-operator-in-javascript
What is the spread operator in JavaScript?
The spread operator is commonly used to make deep copies of JS objects. When we have nested arrays or nested data in an object, the spread operator makes a deep copy of top-level data and a shallow copy of the nested data.
🌐
DEV Community
dev.to › robaguilera › spread-operator-tricks-4g9k
Spread Operator Tricks - DEV Community
September 3, 2018 - Any changes to newNed will not mutate the oldNed variable. However, there is one exception. The spread operator does not preform a deep clone of a nested object.
🌐
Rune Hub
rune.codes › home › tutorials › programming languages › javascript › copying nested objects with the js spread operator
Copying Nested Objects With JS Spread Operator: 2026 Guide | Rune Hub
March 4, 2026 - For immutable state updates in frameworks, manual nested spread is the standard convention. For more on the spread vs rest distinction, see JS spread vs rest operator complete tutorial. For related variable extraction techniques, see advanced array and object destructuring guide. Deep CopyES6Spread OperatorShallow CopyJavaScriptIntermediate JavaScript
🌐
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...
🌐
LinkedIn
linkedin.com › pulse › demystifying-javascripts-spread-operator-guide-pradeepa-kannan
"Demystifying JavaScript's Spread Operator: A Comprehensive Guide"
September 18, 2023 - The spread operator is a versatile feature in JavaScript that simplifies many common programming tasks by providing an elegant way to work with iterable data structures. Limitation or consideration when using spread operator : Shallow Copying: When used to copy objects or arrays, the spread operator performs a shallow copy. This means that it only creates copies of the top-level elements, not nested objects or arrays.
🌐
Prodoit
prodoit.dev › blog › js-notes › 06-object-spread-methods
Object Nesting, spreading, methods and more | Santhosh Bhoopal
September 27, 2024 - If we want to access nested objects, we simply use dot notation ... The spread operator is used to spread across object properties into a new object.
🌐
Dmitri Pavlutin
dmitripavlutin.com › object-rest-spread-properties-javascript
An Easy Guide to Object Rest/Spread Properties in JavaScript
January 3, 2018 - Object spread does a shallow copy of the object. Only the object itself is cloned, while nested instances are not cloned.
🌐
freeCodeCamp
freecodecamp.org › news › javascript-object-destructuring-spread-operator-rest-parameter
JavaScript Object Destructuring, Spread Syntax, and the Rest Parameter – A Practical Guide
February 8, 2021 - The spread syntax performs a shallow copy of the object. This means that none of the nested object instances are cloned.
🌐
Coddy.Tech
coddy.tech › docs › object spread
Runnable JavaScript Docs: Object Spread | Coddy
April 23, 2026 - Runnable JavaScript docs - edit and run every example in your browser, no setup. A practical guide to JavaScript object spread (`...obj`): clone objects, merge them, override properties, and avoid the shallow-copy trap with nested data.
🌐
freeCodeCamp
forum.freecodecamp.org › t › using-spread-operator-to-update-the-state-in-react › 351831
Using Spread operator to update the state in react - The freeCodeCamp Forum
February 20, 2020 - Hi, does copying nested object using spread have different address (reference). We do that so react can know while rendering the dom that there is some change (because of the references are different). But the value we u…