3 ms·
How does the pervasive use of higher-order functions affect debugging? Take this example: const withDagobah = ({ LoadingViewComponent, ErrorViewComp
by chrismorgan 9y ago
How does the pervasive use of higher-order functions affect debugging?
Take this example:
const withDagobah = ({
LoadingViewComponent,
ErrorViewComponent,
PlanetViewComponent
}) =>
class extends React.Component {
…
};
In a language with proper generics, you’d write this instead:
class Dagobah<LoadingViewComponent, ErrorViewComponent, PlanetViewComponent> extends React.Component {
…
}
And then you’d clearly have an object of type Dagobah<LoadingView, ErrorView, PlanetView>, easy to inspect and debug. (And Dagobah<A, B, C> = Dagobah<A, B, C>, whereas withDagobah(A, B, C) ≠ withDagobah(A, B, C).)
(I’ll ignore the topic of type erasure.)
- acemarke 9y agoIf you inspect the component tree using the React DevTools, you'll be able to see exactly what values each component is passing to its children, and what their internal state is. So, use of HOCs adds an extra level of nesting to the component tree, but it should also be very clear in there what each component is passing down.