react-remove-scroll icon indicating copy to clipboard operation
react-remove-scroll copied to clipboard

renderProps / hooks

Open diegohaz opened this issue 5 years ago • 7 comments

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?

diegohaz avatar Mar 09 '19 15:03 diegohaz

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".

theKashey avatar Mar 09 '19 21:03 theKashey

Anyway - maybe we are talking about different aspects. Could you give an example from your mind?

theKashey avatar Mar 09 '19 21:03 theKashey

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.

diegohaz avatar Mar 10 '19 12:03 diegohaz

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.

theKashey avatar Mar 10 '19 21:03 theKashey

theKashey avatar Mar 10 '19 21:03 theKashey

I ended up using this imperative library within React.useEffect. It seems to work well.

diegohaz avatar Mar 12 '19 17:03 diegohaz

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.

theKashey avatar Mar 12 '19 21:03 theKashey

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.

stale[bot] avatar Apr 30 '23 07:04 stale[bot]