-
Notifications
You must be signed in to change notification settings - Fork 889
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
'useLeaflet' hook #571
'useLeaflet' hook #571
Conversation
Hi, I'd rather not add this kind of support for hooks as an afterthought. The context is meant to be used internally by the components of this library and plugins rather than in a public API, I think it would create confusion about its usage and its limitations. |
Hi. Sure. Right now I have 12 files importing As I see my implementation of Could you please expand your understanding of what is wrong with |
I'd also suggest to use const WithLeafletComponent = (props, ref) => (
<WrappedComponent {...props} leaflet={useLeaflet()} ref={ref} />
) instead of const WithLeafletComponent = (props, ref) => (
<LeafletConsumer>
{(leaflet: LeafletContext) => (
<WrappedComponent {...props} leaflet={leaflet} ref={ref} />
)}
</LeafletConsumer>
) |
I agree hooks are great and could be a better way to implement this library, I've started to experiment with this but I think it should be done in a next major version. That said, hooks are new and it seems to me people are still figuring out how to use them and/or trying to use them in places they are not the most relevant. More than adding this To me your answer of wanting to replace HOCs with hooks is not really a use case for this library, it's a project setup preference. So to be clear, I agree that hooks are great and useful for this library. It allows a nice functional composition of the logic rather than extending classes for example and I think it's the way forwards, but I don't think adding this |
Sorry to hear that, I really do not understand what is your concern specifically about What you're saying can be said exactly about Hooks are really not about specific use cases for your library. They are about use cases for programming with react. I consider that problems, which are solved by hooks, are real and are not the same as project preferences. |
So what problem does the |
I'm afraid, I cannot explain better than the react team did. But theses are the things which annoy me in HOCs:
Though afterthought I appreciate your wish to not hurry and take more time thinking on API to have easier maintaining. |
OK thanks for the explanations! |
Thanks! |
Hello @vadzim , I'm sorry to ask but would you mind provide an example ? I'm new in react and a bit lost how to use it. Thanks |
Implemented
useLeaflet
hook.Example:
closes #539