refactor: using useRef in useLocalObservable
Code change checklist
- [ ] Added/updated unit tests
- [ ] Updated
/docs. For new functionality, at leastAPI.mdshould be updated - [ ] Verified that there is no significant performance drop (
yarn mobx test:performance)
Change useState to useRef in useLocalObservable, creating a mutable reference.
⚠️ 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
Hi, could you describe the necessity of that change?
i think useRef is more appropriate, because the mobx observable object is a mutable reference
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.