-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add useRefs
hook
#17
base: main
Are you sure you want to change the base?
Add useRefs
hook
#17
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It needs some tests, primarily because it is new and unproven API but also want to see examples of how it would be used in several scenarios.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you link this to an issue to discuss the actual use case of this hook?
Proposed changes
As your game UI grows, it becomes really difficult to track the instances you want to filter the references - If I had a tree of functions that returns instances, and want to capture one of its descendants, I'd have to pass my
ref
table all the way down the tree just so I could set the reference to be that one instance.The proposed new hook called
useRefs
, eliminates this issue by grabbing theref
table in the currentuseInstance
call. This can only be used insideuseInstance
and will error if done otherwise.Additional comments
useInstance
's callback.ref
table afteruseCallback
is done executing as it shouldn't be mutated anyways. (New hook's behavior also depends on this)