Skip to content

refactor: extract duplicated CSV fetch logic into a single reusable function in useCSVData#103

Open
Harshit-Mishra2212 wants to merge 1 commit into
seetadev:mainfrom
Harshit-Mishra2212:refactor/useCSVData-extract-fetch-logic
Open

refactor: extract duplicated CSV fetch logic into a single reusable function in useCSVData#103
Harshit-Mishra2212 wants to merge 1 commit into
seetadev:mainfrom
Harshit-Mishra2212:refactor/useCSVData-extract-fetch-logic

Conversation

@Harshit-Mishra2212

Copy link
Copy Markdown

📌 Description

In useCSVData.ts, the CSV fetch and parse logic was written out twice in full - once inside the useEffect as fetchCSV, and
again inside mutate. Both functions made the same fetch call to the same URL, used the same PapaParse config, set the same state variables, and logged the same console messages. They were identical in every way.

This meant any change to fetch behaviour, parse config, error handling, or logging had to be applied in two places. The two copies had already drifted slightly in their console.log messages ('Fetching CSV data...' vs 'Manually refreshing CSV data...') even
though they do the same thing.

No related issue.


✅ Changes

  • Refactor

  • Extracted fetch and parse logic into a single loadCSV function wrapped in useCallback

  • useEffect now calls loadCSV directly instead of defining its own copy

  • mutate is now just loadCSV - no separate implementation

  • Extracted the CSV URL into a CSV_URL constant so it is defined once at the top of the file

  • Added useCallback import alongside existing React imports


📷 Screenshots / Demo

Not applicable - internal hook refactor with no UI changes.


Checklist

  • I have tested this code
  • I have added necessary documentation
  • I have linked relevant issue(s)
  • I followed the code style of the project
  • I reviewed my own code

@vercel

vercel Bot commented May 29, 2026

Copy link
Copy Markdown

@Harshit-Mishra2212 is attempting to deploy a commit to the SEETA's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant