From d537e9327513f2b401b9eba124f441122410c921 Mon Sep 17 00:00:00 2001 From: aksh1322 <57146538+aksh1322@users.noreply.github.com> Date: Fri, 2 Aug 2024 20:23:09 +0530 Subject: [PATCH] Add react hooks best practices resources (#6303) * Update hooks-best-practices@mkyU0ug8MXxV4biHuOity.md * Update src/data/roadmaps/react/content/hooks-best-practices@mkyU0ug8MXxV4biHuOity.md --------- Co-authored-by: Kamran Ahmed --- .../hooks-best-practices@mkyU0ug8MXxV4biHuOity.md | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/data/roadmaps/react/content/hooks-best-practices@mkyU0ug8MXxV4biHuOity.md b/src/data/roadmaps/react/content/hooks-best-practices@mkyU0ug8MXxV4biHuOity.md index ba63b603b..ba398821a 100644 --- a/src/data/roadmaps/react/content/hooks-best-practices@mkyU0ug8MXxV4biHuOity.md +++ b/src/data/roadmaps/react/content/hooks-best-practices@mkyU0ug8MXxV4biHuOity.md @@ -1,15 +1,6 @@ # Hooks Best Practices -1. Use Hooks at the Top Level: Always call Hooks at the top level of your React function, before any early returns. This ensures that Hooks are called in the same order each time a component renders. -2. Only Call Hooks from React Functions: Hooks should only be called from React function components or custom Hooks, not from regular JavaScript functions. -3. Keep Hooks Pure: Hooks should not cause side effects. Use useEffect for side effects like data fetching or subscriptions. -4. Optimize Performance: Use useMemo and useCallback to memoize expensive calculations and functions to avoid unnecessary re-renders. -5. Encapsulate Logic in Custom Hooks: If you find yourself using the same logic in multiple components, consider creating a custom Hook to encapsulate that logic. -6. Use Dependency Arrays in useEffect: Always specify dependencies in useEffect to avoid unnecessary re-runs of the effect. -7. Avoid Overusing State: Use state sparingly and only when necessary. Too many state variables can make your component complex and hard to manage. - -Here are some useful resources to refer to: +Learn the best practices for using React hooks from the following resources: - [@article@React Hooks Cheat Sheet: Best Practices with Examples](https://blog.logrocket.com/react-hooks-cheat-sheet-solutions-common-problems/) -- [@article@React Hooks Cheat Sheet: The 7 Hooks You Need To Know](https://www.freecodecamp.org/news/react-hooks-cheatsheet/) -- [@article@React Custom Hooks: Best Practices and Examples](https://utopia-insights.dev/react-custom-hooks-best-practices-and-examples/) +- [@article@React Custom Hooks: Best Practices and Examples](https://utopia-insights.dev/react-custom-hooks-best-practices-and-examples/) \ No newline at end of file