ethanselzer / react-cursor-position

A React component that decorates its children with mouse and touch coordinates relative to itself.
https://ethanselzer.github.io/react-cursor-position
MIT License
143 stars 35 forks source link

Support renderProp? #19

Open Secretmapper opened 6 years ago

Secretmapper commented 6 years ago

This should allow more control of the properties, i.e. pass the coordinate information to grandchildren, etc.

https://reactjs.org/docs/render-props.html

ethanselzer commented 6 years ago

@Secretmapper - Thanks for suggesting the render-props pattern. I think if I were creating this library today, I might use it. Other than the convenience of passing props directly to deep descendants, I'm wondering what you think the benefits of the render-props pattern are over the currently implemented "decoration" pattern.

Secretmapper commented 6 years ago

I'm not really sure 🤔. The real main use case I can think of is with props passing to deep descendants, as I have a use case where I need to keep track of the coordinates in a larger container, but only a deeper component handles the data.

There's already a way to do it in user space in the current API as I can write a component that wraps them in this way but it's a level of indirection that would be solved with renderProp.

If ever, do you think it best to migrate or keep both APIs and let the user decide? I'll try to submit PR soon.