Skip to content

refactor(useCounter): modify useCounter props structure #222

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 1 commit into
base: main
Choose a base branch
from

Conversation

JeongHwan-dev
Copy link
Contributor

@JeongHwan-dev JeongHwan-dev commented Apr 27, 2025

Overview

Refactor: Change Parameter Structure of useCounter Hook

Improved the API of the useCounter hook to make it more intuitive and easier to use. Previously, all settings were inside an options object, but now the most frequently used initialValue parameter has been separated as the first argument.

Before:

useCounter({ initialValue: 10 });
useCounter({ 
  initialValue: 5, 
  min: 0, 
  max: 10,
});

After:

useCounter(10);
useCounter(5, { 
  min: 0, 
  max: 10,
});

Refactoring Reasons:

  1. Improved Readability: Separating the most important parameter (initial value) as a positional argument improves code readability.
  2. Enhanced Usability: Basic use cases become more concise. When only specifying an initial value, it can be used directly without an options object.
  3. Conforming to React Hooks Conventions: Official React hooks (useState, useReducer, etc.) follow the pattern of receiving initial values as the first argument. This change aligns with common conventions in the React ecosystem.

This change is purely for API structure improvement, with no functional changes.

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?

@codecov-commenter
Copy link

codecov-commenter commented Apr 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (8aecbf4) to head (f18c5a7).
Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #222   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           33        33           
  Lines          839       839           
  Branches       254       254           
=========================================
  Hits           839       839           
🚀 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.

@JeongHwan-dev JeongHwan-dev force-pushed the refactor/modify-use-counter-props branch from f5271ed to f18c5a7 Compare April 27, 2025 06:21
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