ctrlplusb / react-sizeme

Make your React Components aware of their width and height!
MIT License
1.95k stars 94 forks source link

Multiple SizeMe components inside one another? #206

Closed EfstathiadisD closed 3 years ago

EfstathiadisD commented 3 years ago

I have a situation where I have a Parent Component that has a variable width. Based on some external conditions. I want one <SizeMe> component attached to that.

Then I have a map over of list of items. I want to attach a second SizeMeon each of them and have it display something based on the condition that the width of the parent minus the width of the child is more than 0. Else I want to render another item saying 6 more items...

Here is the code I have so far. I manage to have 2 SizeMe components, but the inner one is not respecting its child width rather than taking the width of the parent.

Here is the Code Sandbox example I have so far. Any ideas on how to achieve my scenario? Is there a possibility I can attach a ref to the in order to listen to that one? I don't see such an option though..