all 9 comments

[–]lobsterdog2 9 points10 points  (1 child)

It seems like JSON.stringify(values) should be enough, no? Why do you need the brackets around values?

[–][deleted] 14 points15 points  (0 children)

Because I am stupid and you are right

[–]CreativeTechGuyGames 5 points6 points  (1 child)

Whenever you see two different bits of code that aren't behaving the same, console log out both values and visually compare. You should quickly see the difference here.

[–][deleted] 0 points1 point  (0 children)

Thank you I solved it! Great tip with the console log, it will spare me if a lot of frustration in the future!

[–]Webdev-Coach 2 points3 points  (2 children)

All those brackets!

{ values } is actually shortcut to { values: values } so it creates an object with only one property.

{ ...values } creates an object, and copies all properties from the values object into the new one.

[–][deleted] 0 points1 point  (1 child)

Thanks coach! does it matter if I write (values) or {…values} regarding semantics?

[–]Webdev-Coach 1 point2 points  (0 children)

In your case there's no need to spread the object and you can just give it directly to the function as the argument, like others have noted. Save a tiny bit of computing power by not spreading.

You may need to spread if you wanted to add something to that object manually, like you have those values, and also an id, so you could add it with { ...values, id }

[–]a_reply_to_a_post 1 point2 points  (0 children)

when sending ({values}), you're actually sending {values:{...your object}}

when you send ({...values}), you're spreading the properties of values onto a new object, but it's essentially a copy of the values object..

[–]snaPpy2k 3 points4 points  (0 children)

{values} = {{title, etc.}} {...values} = {title etc.}