[RFC] should we add callbacks to the useMap and useMapsLibrary hooks? #159
usefulthink
started this conversation in
Ideas
Replies: 1 comment
-
/cc @leighhalliday would love to hear your thoughts on this if you can spare a few minutes. Note that I'd want to implement this in a fully backward compatible way. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
An Idea for how to simplify the typical use-cases of the
useMap
anduseMapsLibrary
hooks just crossed my mind and I would love to hear what others think about this.The most common use-case for the
useMap
hook follows this pattern:This can be simplified if we move the useEffect into the useMap hook, allowing users to shorten the code to
The biggest issue with this would be that we can't specify the dependencies for the effect in a clean way, so I guess an alternative would be to put this into a new hook
useMapEffect()
which would follow the structure ofuseEffect()
and make the semantics of the dependencies array and the returned cleanup-function a bit clearer:Something similar can be done for the typical use-case of
useMapsLibrary
:Since the cleanup-function will typically not be needed with
useMapsLibrary
, we could go even one step further and pass through the value returned by the callback, so the example above would become:what do you think about these? Is that too far from what react usually does or could those be useful?
Beta Was this translation helpful? Give feedback.
All reactions