Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

333
Views
Which is the best way to create a reusable skeleton component?

I'm using the react-loading-skeleton and I'm trying to create a reusable component on top of the <Skeleton /> component of this library.

The reason that I'm trying to create something like this is because I don't like the approach of react-loading-skeleton, which is something like this:

<div>
    <h1>{props.title || <Skeleton />}</h1>
    {props.body || <Skeleton count={10} />}
</div>

I think the code would get hard to understand and repetitive.

My idea is to create a custom JSX component that has the following props:

  1. Component - To render the component when the skeleton is not needed
  2. condition - To check if it should render the component or the skeleton
  3. skeletonCount - just a prop of the skeleton library
  4. ...props - to receive all the additionals props that Component may have.

I wanna know if this is a good approach because I was getting some typescript errors related to ...props. enter image description here

This is the component:

import React from 'react';
import Skeleton from 'react-loading-skeleton';
import type { SkeletonProps } from './types';

export const SkeletonHandler: React.FC<SkeletonProps> = ({
  Component,
  condition,
  skeletonCount,
  ...props
}) => {
  return condition ? (
    <Component {...props} />
  ) : (
    <Skeleton count={skeletonCount} />
  );
};

My types.ts:

export type SkeletonProps = {
  Component: React.JSXElementConstructor<any>; //idk if this is the correct type to use tbh.
  skeletonCount: number;
  condition: boolean;
};

Usage:

<SkeletonHandler Component={TierTitle} variant="h4" color="black" bold>
  {clientName}
</SkeletonHandler>

PS: variant, color, bold and client name are all values that were in the component.

Please, let me know if there is a better way of solving this problem.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!