mobx icon indicating copy to clipboard operation
mobx copied to clipboard

refactor: using useRef in useLocalObservable

Open misaeldossantos opened this issue 3 years ago • 2 comments

Code change checklist

  • [ ] Added/updated unit tests
  • [ ] Updated /docs. For new functionality, at least API.md should be updated
  • [ ] Verified that there is no significant performance drop (yarn mobx test:performance)

Change useState to useRef in useLocalObservable, creating a mutable reference.

misaeldossantos avatar Jul 30 '22 16:07 misaeldossantos

⚠️ No Changeset found

Latest commit: 2c326fa087950e099fb5d048bfbe8cc212c05f1c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Jul 30 '22 16:07 changeset-bot[bot]

Hi, could you describe the necessity of that change?

kubk avatar Jul 30 '22 19:07 kubk

i think useRef is more appropriate, because the mobx observable object is a mutable reference

misaeldossantos avatar Sep 25 '22 02:09 misaeldossantos

I'd say that both useState and useRef are appropriate here because they remember their data after re-renders. The approach with useRef is just more verbose (hence more bytes in the bundle). Thank you for the desire to improve things, but I think this change is not necessary.

kubk avatar Sep 25 '22 11:09 kubk