Skip to content

Commit

Permalink
fix build error with more readable code
Browse files Browse the repository at this point in the history
not related with the change but resulting in build error
  • Loading branch information
kouloumos committed Nov 7, 2024
1 parent f4b3274 commit 12b3c96
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/context/SearchQueryContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,17 @@ export const SearchQueryProvider = ({
}, [rawSearchQuery]);

const page = useMemo(() => {
return pageQuery ? parseInt(pageQuery) - 1 ?? 0 : 0;
// Handle empty or invalid input
if (!pageQuery) {
return 0;
}

// Convert to number and validate
const parsedPage = Number(pageQuery);
const isValidPage = !isNaN(parsedPage) && parsedPage > 0;

// Convert from 1-based to 0-based index, or default to 0
return isValidPage ? parsedPage - 1 : 0;
}, [pageQuery]);

const resultsPerPage = sizeQuery
Expand Down

0 comments on commit 12b3c96

Please sign in to comment.