Frontendx
README.md
SOLUTION.md
main.tsxentry
App.tsx
App.css
index.html
vite.config.ts
Installed
react@^19.2.0
react-dom@^19.2.0

Higher-Order Component (HOC) Pattern

mediumreactpatternshocReact Patterns

Description

Implement a Higher-Order Component (HOC) called withLoading that adds loading state functionality to any component.

Example 1:

withLoading(Component) returns a new component
The new component shows loading spinner when isLoading is true
Otherwise renders the original Component with all props passed through

Example 2:

const EnhancedComponent = withLoading(DataComponent);
<EnhancedComponent isLoading={true} data={...} />
// Shows loading spinner
<EnhancedComponent isLoading={false} data={...} />  
// Renders DataComponent with data prop

Constraints

  • Create withLoading HOC function
  • HOC should accept a component and return a new component
  • New component shows loading indicator when isLoading prop is true
  • All other props should be passed through to the wrapped component
  • Use the HOC to enhance a display component
HOC is a function that takes a component and returns a new enhanced component
Test Results

Higher-Order Component (HOC) Pattern

Implement a Higher-Order Component to add loading state to any component.