bvaughn / react-resizable-panels

https://react-resizable-panels.vercel.app/
MIT License
3.99k stars 144 forks source link

Provide hook to consume PanelGroup state #404

Closed yangshun closed 2 months ago

yangshun commented 2 months ago

Hi Brian, what do you think about providing a hook to consume a PanelGroup's internal state (dragState) like whether the panel is being resized and the handle ID is being dragged? My use case is to disable certain interactions within Panels when the groups are being resized.

I could track that state myself using onDragging/onResize prop but I feel it'd be useful for the library core to provide that information.

bvaughn commented 2 months ago

Hmm. I’m not generally a fan of providing redundant ways to do a something unless it’s a really common ask (and also difficult to do in user-space). It can make maintenance more difficult and can even make APIs/docs more confusing. In this case I’m inclined towards leaving things as-is, but I’ll leave the issue open for a couple of days to consider it.

bvaughn commented 2 months ago

I've given this some consideration and decided against it for two reasons:

  1. The drag state object is meant to be internal to this library so I wouldn't want to expose it directly. I could expose only parts of it, but-
  2. Exposing a value like this through a hook would require using React context, which would add addition work (React updates) for every app that uses this library, and I expect this hook would only be used in a rare occasions.

Best to just add this in user space I think. :)

yangshun commented 2 months ago

Thanks for considering it and for the explanation :)