Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloning objects (Object spread) #24

Open
akinsho opened this issue May 25, 2018 · 4 comments
Open

Cloning objects (Object spread) #24

akinsho opened this issue May 25, 2018 · 4 comments

Comments

@akinsho
Copy link

akinsho commented May 25, 2018

Hi,

Hope learning react is going okay, having a look through the code and I noticed that here you are cloning an object by JSON.stringifying then parsing a simpler and arguably more readably solution would be to use Object spread notation ... (not sure if your current build strategy supports it) example: let objClone = { ...obj };

@oliverjam
Copy link

We didn't set up Babel for Object spread support, but you could use Object.assign to achieve the same result.

Actually since cells is an array you can use array spread to copy it ([...array])

@isnotafunction
Copy link
Collaborator

Thanks so much for these suggestions! I thought spread does shallow copying, so just curious if that would ever be a problem?

@oliverjam
Copy link

Yeah it does do shallow copying, but in this case that would be fine. If you have nested objects/arrays you would need to do something a bit more complex

@isnotafunction
Copy link
Collaborator

Thanks! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants