Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

335
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda