Skip to content

feat(utils): add renderTimes util #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

JeongHwan-dev
Copy link
Contributor

@JeongHwan-dev JeongHwan-dev commented Jun 28, 2025

Overview

What

Added a new utility function renderTimes that renders components a specified number of times, useful for creating repeated UI elements like lists, grids, pagination items, or skeleton loaders.

Why

This utility helps developers avoid manual duplication when creating repeated UI patterns. Instead of writing repetitive JSX or using verbose Array.from constructs, developers can use this clean, declarative function to render components multiple times with proper indexing.

Usage Examples

Skeleton UI Rendering:

// ❌ Before - Manual repetition (not maintainable)
function ProductListSkeleton() {
  return (
    <div className="product-grid">
      <div className="product-card-skeleton">
        <div className="skeleton-image" />
        <div className="skeleton-title" />
        <div className="skeleton-price" />
      </div>
      <div className="product-card-skeleton">
        <div className="skeleton-image" />
        <div className="skeleton-title" />
        <div className="skeleton-price" />
      </div>
      <div className="product-card-skeleton">
        <div className="skeleton-image" />
        <div className="skeleton-title" />
        <div className="skeleton-price" />
      </div>
      {/* ...repeat 3 more times */}
    </div>
  );
}

// ❌ Before - Using Array.from (verbose and less readable)
function ProductListSkeleton() {
  return (
    <div className="product-grid">
      {Array.from({ length: 6 }, (_, index) => (
        <div key={index} className="product-card-skeleton">
          <div className="skeleton-image" />
          <div className="skeleton-title" />
          <div className="skeleton-price" />
        </div>
      ))}
    </div>
  );
}

// ✅ After - More readable and intention-revealing
function ProductListSkeleton() {
  return (
    <div className="product-grid">
      {renderTimes(6, (index) => (
        <div key={index} className="product-card-skeleton">
          <div className="skeleton-image" />
          <div className="skeleton-title" />
          <div className="skeleton-price" />
        </div>
      ))}
    </div>
  );
}

Checklist

  • Did you write the test code?
  • Have you run yarn run fix to format and lint the code and docs?
  • Have you run yarn run test:coverage to make sure there is no uncovered line?
  • Did you write the JSDoc?

@JeongHwan-dev JeongHwan-dev force-pushed the feat/add-render-times branch from f855f8d to f67cc9d Compare June 28, 2025 06:02
@codecov-commenter
Copy link

codecov-commenter commented Jun 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (5bdb4ff) to head (17527f9).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #262   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           37        38    +1     
  Lines         1093      1096    +3     
  Branches       324       326    +2     
=========================================
+ Hits          1093      1096    +3     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants