Skip to content
This repository has been archived by the owner on May 15, 2022. It is now read-only.

Why do a deep clone in update? #58

Open
disambiguator opened this issue May 7, 2020 · 0 comments
Open

Why do a deep clone in update? #58

disambiguator opened this issue May 7, 2020 · 0 comments

Comments

@disambiguator
Copy link
Contributor

The handle update function's behavior confuses me a little bit. Looks like the whole data object is deep cloned before setting the new property here.

The documentation in the README shows:

  // Update current state with changes from controls
  handleUpdate = newData =>
    this.setState(prevState => ({
      data: { ...prevState.data, ...newData }
    }));

which I took to imply that newData would only have the updated values according to the recent event.
The deep cloning has some other downstream issues, such as affecting object equality and causing a lot of unnecessary hooks to fire.

I've made a PR which changes this to instead just populate newData with the updated key/value, it works for me locally and fixes a lot of my bugs.
https://github.com/claus/react-dat-gui/pull/57/files

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

No branches or pull requests

1 participant