react-remove-scroll
react-remove-scroll copied to clipboard
renderProps / hooks
Hi @theKashey. I found this library while researching for solutions to build accessible dialogs. Thanks for your work.
Do you have plans to provide render prop and/or hooks API?
It's not possible - there is no place for API such this.
RemoveScroll
should be "declarative" not only to make application a bit more accessible, but to prevent real incidents - last year we have a few, with a page scroll locked when it should not.
Scroll/Focus locks are quite dangerous things, let's keep API a bit more "safe".
Anyway - maybe we are talking about different aspects. Could you give an example from your mind?
My use case is that I'm shipping a bunch of hooks. They return props like ref
and event handlers. I can't use this library right now because (1) it's a component and (2) I can't combine props.
The only way to expose hooked API is to rewrite everything to hooks, then redo component API using hooks, and then export component and hooked API for everyone. In the same time it will reduce the package size. The problem is - I would have to apply this to the all my "locking" stack, as long as they supposed to work together and share common libraries. So - it would take time.
PS: I am still not sure about "safety" of this approach.
- As always - it's not a good idea to massively migrate to hooks until enzyme supported them.
I ended up using this imperative library within React.useEffect
. It seems to work well.
body-scroll-lock is not bad, I would recommend scroll-lock as a better alternative.
But the main driver for react-remove-scroll
creation were portals. And that's one of the reasons why it is "component" based - I need to hook into React Event propagation system. Nowadays portals are everywhere, and every second modal contain a react-based select/dropdown - so it's a much-have.
This issue has been marked as "stale" because there has been no activity for 2 months. If you have any new information or would like to continue the discussion, please feel free to do so. If this issue got buried among other tasks, maybe this message will reignite the conversation. Otherwise, this issue will be closed in 7 days. Thank you for your contributions so far.