You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
React Hook Extended Kit is a comprehensive utility library aimed at enhancing React applications with a collection of custom hooks. Developed by Romain Portanguen under the MIT licence, it introduces advanced features such as state management, online state tracking, dark mode implementation, performance optimisation and more. By simplifying the integration of features such as window resizing, media queries and clipboard interactions, this open-source project streamlines front-end development and provides a valuable resource for developers looking to efficiently enhance their React projects.
🧩 Features
Feature
Description
⚙️
Architecture
The project adopts a modular architecture with centralized hooks collection, efficient testing configurations, and streamlined entry points. This architecture enhances extensibility and integration in React projects.
🔩
Code Quality
The codebase maintains high code quality and adheres to best practices with consistent formatting, linting, and testing. It follows TypeScript standards and leverages efficient code minification techniques.
📄
Documentation
The project provides comprehensive documentation through the generation of documentation via the Typedoc API, type definitions and clear online comments. This improves readability and ease of use for developers using the repository; in addition, a full version of the documentation is also available in a Docsify interface. Link available in description.
🔌
Integrations
Key integrations include Jest for testing, TypeScript for typing, and ESLint for code analysis. These integrations streamline development processes and ensure code correctness.
🧩
Modularity
The codebase demonstrates high modularity with each hook encapsulated as a separate module, promoting code reusability and easy maintenance in React projects.
🧪
Testing
Testing frameworks and tools like Jest, React Testing Library, and @testing-library/react-hooks are used to ensure robust test coverage and maintain code reliability.
⚡️
Performance
The project emphasizes efficiency through minification scripts, throttle and debounce hooks for performance optimization, and clean event handling for improved responsiveness.
🛡️
Security
Data protection measures include local/session storage handling, event listener management, and error handling to prevent unauthorized access and ensure secure data management.
📦
Dependencies
Key external libraries and dependencies include Prettier, TypeScript, ESLint, Jest, and various testing utilities. These libraries enhance development workflows and maintain code quality.
🚀
Scalability
The project exhibits scalability with hooks catering to varied functionalities, state management, performance optimization, and user interaction handling, supporting increased traffic and load demands efficiently.
Implements Jest configuration in the react_hook_extended_kit repo. Defines test environment, file transformations, coverage settings, and more for efficient testing.
The code file in react_hook_extended_kit/src/index.ts serves as the central entry point for the React Hook Extended Kit repository. It acts as a bridge, organizing and exporting essential functions and utilities from various hook modules within the project. By consolidating these hooks, the index.ts file streamlines access to the extended functionalities provided by the repository, fostering easier integration and enhanced extensibility in React projects.
Defines utility for React hooks, enhances with centralized hooks collection, emphasizes build, test automation, and documentation, enabling seamless integration and maintenance.
Generates API documentation for React Hook Extended Kit by specifying entry points and theme. Excludes private, protected, and external items, enhancing readability and usability for developers.
Optimize TypeScript configuration for React project to enforce strict typing and ES6 features. Set up module resolution, JSX support, and output directory. Exclude test files for cleaner build output.
Implement minification for JavaScript files within the dist directory. This script reads, minifies, and writes files using Terser. Automatically applies to all.js files recursively.
Enables sponsorship options for the repository through various funding platforms like GitHub Sponsors, Patreon, and others by specifying usernames or links. Facilitates community support and financial contributions for the open-source project.
Exports essential custom hooks for various functionalities in the parent repository. These hooks enhance user experience by providing features like click handling, state management, dark mode, network requests, and storage options.
Validates useToggle hook for initializing toggle state, toggling between true and false values, and setting a custom initial value. The tests ensure correct functionality and behavior.
Enables toggling boolean states in React components using a custom hook. Directly accessible in the hooks directory, it simplifies managing the state by returning an array with the current value and a toggle function.
Enables retrieving current window size in React components. The useWindowSize hook in the src/hooks/ui directory dynamically updates width and height based on window resizing, enhancing UI responsiveness.
Enables monitoring of media queries in React components to dynamically adjust UI based on screen size. It offers a reusable useMediaQuery hook that returns a boolean indicating if the query matches, simplifying responsive design implementation.
Initializes with default value, toggles dark mode & updates localStorage, and reads initial state from localStorage. Crucial for ensuring correct functionality of dark mode feature in the React app.
Tests the useFetch hook for fetching data, handling errors, and non-200 responses. Mocks global fetch function and asserts data, loading state, and errors returned by the hook.
Enables fetching data from an API with loading and error handling. Achieves this by providing a custom hook useFetch with parameters for URL and options. Returns an object with data, error, and loading states for easy integration into components.
Enables observing element visibility using Intersection Observer API in React. Returns a reference to the observed element and a boolean for visibility status. Helps lazy load images efficiently in the React application.
Detects user inactivity using custom hook useIdle which returns boolean state. Monitors mouse/keyboard events to reset timeout, signaling user idleness. Key feature in react_hook_extended_kit for managing idle state in components dynamically.
Tests use useIdle hooks functionality to confirm initial active state, transition to idle after timeout, reset on activity, and cleanup on unmount. Leveraging @testing-library/react-hooks and Jests fake timers ensure accurate verification of idle state transitions.
Enables event listener management in React components. Attaches event handlers to specified elements to trigger actions based on events. Facilitates clean and efficient handling of user interactions within the parent repositorys architecture.
Implements a custom hook for clipboard operations, providing functions to copy text to the clipboard and read text from it. Streamlines clipboard interactions in React components and enhances user experience.
Tests copying and reading text from clipboard are covered by useClipboard hook in the parent repository. The tests validate the functionality using @testing-library/react-hooks. This contributes to ensuring the reliability of the clipboard interaction feature.
Tests the useGeolocation hook by simulating successful and failed geolocation requests. Verifies default state, updates with position on success, and handles errors. Also confirms clearing of watch on unmount.
Tests use a mock IntersectionObserver to validate the useIntersectionObserver hook behavior. Tests include element observation, intersection detection, option updates, and proper unobserving and disconnecting.
Triggers handler on event, cleans up on unmount, supports specific element events, updates handler changes, and handles window events by default. Part of the react_hook_extended_kit repositorys architecture.
Enables tracking user geolocation with customizable options. Implements a geolocation hook returning coordinates and errors. Facilitates real-time position updates using browser geolocation API.
Enables tracking and retrieving the previous value of a variable using a custom React hook. Facilitates monitoring state changes and building dynamic UI components within the open-source React Hook Extended Kit repository structure.
Enables creation of a counter state with increment, decrement, and reset functions. Supports initializing value and returns current count with corresponding actions. Ideal for managing counter UI components in React applications within the hooks directory.
Initializes at 0, increments, decrements, and resets count. Integrated with @testing-library/react-hooks for robust testing within the React Hook Extended Kit repository.
Enables synchronization of state with localStorage using a custom hook. Maintains values under specified keys, providing getters and setters for updates. Aids in persisting and manipulating data for React components.
Tests useLocalStorage hook for initializing, updating, and retrieving values from localStorage, handling errors gracefully. Maintains expected behavior and error scenarios of the hook within the React applications hooks directory.
Enables synchronization of state with sessionStorage by storing and retrieving values based on a specified key. Offers a function to update and maintain state. Ideal for persisting user data in React components.
Tests useSessionStorage hook for initialization, updates, retrieval, and error handling. Validates proper sessionStorage behavior with different value scenarios, ensuring robust data handling in the React application.
Ensures callback is executed at intervals, stops interval with null delay, and handles changing delay values. Maintains expected callback invocation counts in different scenarios.
Implements a custom hook useClickOutside detecting clicks outside a specified element. Ensures accessibility and enhances UX by executing a callback when a click occurs outside the component, fostering a seamless user experience in React applications.
Tests use useClickOutside hook to verify click behavior. First test checks handler call when clicking outside element. Second test ensures handler isnt called when clicking inside element. Core functionality validated through rendering hooks and simulating user interactions.
Defines a custom throttle hook in the react_hook_extended_kit repo. Throttles a value input at a specified limit to enhance performance. Key features include handling value updates and managing timing constraints, ensuring optimal reactivity in user interfaces.
Tests the throttling behavior of the useThrottle hook, ensuring it delays updates based on specified limits and handles rapid value changes correctly. Also validates that timeouts are cleared on unmount and immediate updates work when the remaining time is zero.
Enables tracking of browser online status with a custom hook. Maintains state and event listeners for online/offline changes. Crucial for real-time online status visualization in React components within the repositorys architecture.
Tests the usePageVisibility hook to ensure it accurately detects page visibility changes. Verifies correct return values for both visible and hidden page states.
Tests for useOnlineStatus hook validate online/offline status accuracy. Simulates online/offline events to assert correct boolean return. Demonstrates expected behavior under network status changes within the parent repositorys React hooks architecture.
Enables tracking page visibility with a custom hook in the React project. Monitors if the page is visible and adjusts video playback accordingly. Enhances user experience by controlling video behavior based on page visibility status.