Closed Kushagra102 closed 1 year ago
Name | Link |
---|---|
Latest commit | 4ec9b846775997ea8cb3339ecb7b0d9fc7107453 |
Latest deploy log | https://app.netlify.com/sites/devempire/deploys/64a56f225c3d9d00081755b5 |
Deploy Preview | https://deploy-preview-340--devempire.netlify.app |
Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
@swapnilsparsh please review this pr.
Description
Fixes #272
Reduced re-renders: In the old code, both the
filterOptions
anddisplayCards
were recalculated on every render, regardless of whether their dependencies had changed. In the new code, these calculations are triggered only when the dependencies (searchTerm
,pageNumber
,filteredPageNumber
) change. This optimization reduces unnecessary calculations and re-renders, leading to better performance.Improved filtering logic: The filtering logic in the new code is simplified and more efficient. Instead of combining the
head
andabout
properties into a single string and usingincludes()
, the new code directly checks if the search term is included in thehead
orabout
properties of each data item. This avoids unnecessary string concatenation and improves filtering performance.Minimal state updates: The new code minimizes state updates by updating the
filterOptions
anddisplayCards
only when necessary. It avoids updating the state when the search term is empty and the filter options remain the same.Consolidated
useEffect
hooks: The new code consolidates the two separateuseEffect
hooks into one. This consolidation reduces the number of effect callbacks and simplifies the code structure, leading to better maintainability.Simplified highlight search term: The new code simplifies the logic for highlighting the search term by using a regex replacement. It avoids unnecessary function invocations and string manipulations, resulting in improved performance.
Overall, these optimizations aim to reduce unnecessary calculations, minimize state updates, simplify logic, and improve the overall performance of the component.
Checklist