Are there any differences between these two pieces of code performance or bug wise?

I don't believe they do, but I found the second snippet in my codebase, so I wanted to be sure that I wasn't going to break something that I didn't try. Everything seems fine when I try it myself on my local server and test the functionality of what is being updated, but wanted to know if I was missing something, or some practice, by adding an empty array first
this.setState({ user: { ...(response || {}), ...data } });
this.setState({ user: { ...(response || {}), ...data } });
this.setState({ user: { ...response, ...data } });
this.setState({ user: { ...response, ...data } });
2 Replies
theo (t3.gg)
theo (t3.gg)3y ago
Depends on what falsy value response can be
{...false}
{...false}
^ will fail I think So the || ensures you're spreading a "valid object" on any falsy value for response
Kyle
KyleOP3y ago
sick, thanks.
Want results from more Discord servers?
Add your server