-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 deps and position field in VarData #4518
add deps and position field in VarData #4518
Conversation
…rder_of_hooks_and_memoized_evt_trigger
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.
i'm overall not crazy about packing more stuff in VarData because these fields do seem to have a pretty niche use in the framework... but i don't have an alternate suggestion that's better, so i think we can be pragmatic and take this.
I sort of agree on this, that's why at first I tried to pass the position to a HookVar with special logic, but in the end passing them through VarData made code much cleaner and easier to read. Also even if they are niche, they won't impact the majority of people who don't need them so it should be fine. |
match the name of the enum
When rendering hooks, some use case are not covered with the current hooks API.
This PR add two fields,
deps
andposition
to VarData that allow some controls on how to render hooks, both in relation to theuseCallback
generated by StatefulComponent.Problem 1:
add_hooks
, when wrapped in useCallback, your event handler will not update its data if thehook_name
is not added to the dependency array.Solution:
Passing the name of the hook in the newdeps
props.Problem 2:
deps
for example), so the hook need to be defined BEFORE.Solution:
Inside a hook, pass eitherHooksPosition.PRE_TRIGGER
orHooksPosition.POST_TRIGGER
to theposition
props.