markdalgleish/redial

provideHooks on nested components are ignored.

pastelsky opened this issue · 3 comments

My routes look like

<Route path="/" component={ App }>
    <IndexRoute component={ Home } />
    <Route path="/search" component={ Search } />
  </Route>

provideHooks on and work just fine. But for any component inside either of these handlers, no call is made to the fetch hooks. Is this expected?

dlmr commented

Yes, this is the expected behaviour.

The components that match have access to is your route components so redial has no way to inspect further down your component structure.

Redial accepts an array of components, it's up to you to provide that structure.

I deliberately avoided increasing the scope of this library to cover that use case, particularly because it's not something I'm interested in supporting long term. It might be worth writing a little library that flattens a tree of components into an array and publishing that to npm yourself.

RIP21 commented

Sorry for reviving this thread. But if it has clue about problems with High Order Components (HoC) or just Wrappers over others components there is a fix.
For example, if you have HOC which is wrapping your secured page component and checks authorization first before render a secured page, there is a problem that hooks on this wrapped components are not working. It can be solved with this lines of code

    if (WrappedComponent['@@redial-hooks']) {
      AuthWrapper['@@redial-hooks'] = WrappedComponent['@@redial-hooks'];
    }

It will pull hooks up to the wrapper (HOC) so all of them will be triggered properly :)