React Higher Order Components in depth
franleplant
1.6K34

as to HOC accessing a ref of WrappedComponent:

is there any convention how layers of HOCs should be able to access this ref? im thinking about passing down wrapperRef function with each HOC just hooking into it

basically each would check for wrapperRef in props, if not there then create one and use, if already available, just create a new one wrapping previous one, the chain would be automatically stopped on the WrappedComponent itself, as its not HOC itself

the one downside I can think of is that the WrappedComponent gets wrapperRef in its props, so its a little bit leaky

wondering if there is any established convention for this kind of thing, basically I need to A and B to have access to C’s ref in compose(A, B)(C) pattern

Show your support

Clapping shows how much you appreciated Mateusz Burzyński’s story.