Home > @cascadiacollections/fluentui-compat
fluentui-compat package
Classes
|
Class |
Description |
|---|---|
|
Ultra-optimized Async utility class designed for high-performance React applications. This class provides memory-efficient management of asynchronous operations with automatic cleanup on disposal. It's particularly useful for preventing memory leaks in React components where async operations might continue after component unmounting. Key performance features: - ID pooling to reduce memory allocations - Batch timer operations to minimize system calls - Window reference caching to reduce DOM queries - Optimized state management in throttle/debounce functions - Development-time performance monitoring | |
|
Ultra-optimized EventGroup utility class for managing multiple event listeners. This class provides centralized management of DOM event listeners with automatic cleanup on disposal. It's particularly useful in React components for preventing memory leaks from forgotten event listeners. Key performance features: - Efficient event tracking using Map for O(1) lookups - Automatic cleanup of all listeners on dispose - Support for both function callbacks and object methods - Proper handling of event listener options - Type-safe event management with TypeScript - Window reference caching to reduce DOM queries **Performance considerations**: - Uses Map for O(1) event lookup and removal - Minimal memory allocations per event - Efficient batch cleanup on dispose - No memory leaks from orphaned listeners **React integration**: While this class can be used directly, consider using |
Functions
|
Function |
Description |
|---|---|
|
Creates an optimized bundled icon component that renders either a filled or regular icon based on the | |
|
Creates a highly optimized memoizer for single-argument functions where the argument is an object or function. Uses WeakMap for automatic memory management. This is ideal for functions that transform objects/functions and need automatic cleanup when the source objects are garbage collected. | |
|
Gets the window object associated with a DOM element. Returns undefined if the element is not in a browser environment. This is a minimal implementation for use with the Async class, providing cross-environment compatibility. | |
|
memoizeFunction(fn, maxCacheSize, ignoreNullOrUndefinedResult) |
Highly optimized memoization function that caches results based on argument identity. Provides configurable cache size limits and automatic memory management. Key performance optimizations: - Uses WeakMap for automatic garbage collection of object arguments - Efficient primitive value caching with shared dictionary - Configurable cache size limits to prevent memory leaks - Global reset counter for bulk cache invalidation - Fast argument normalization |
|
Reset the global ID counter. Useful for testing. ⚠️ **Warning**: This should only be used in tests. Calling this in production code can lead to duplicate IDs and accessibility issues. | |
|
Reset all memoizations by incrementing the global reset counter. This is more efficient than clearing individual caches. | |
|
Hook to provide an Async instance that is automatically cleaned up on dismount. This implementation is optimized for: - **Memory efficiency**: Uses | |
|
Hook to store a boolean value and generate callbacks for setting the value to true, false, or toggling it. This hook is optimized for performance using idiomatic React patterns: - The identity of the callbacks will always stay the same across renders - Uses | |
|
Hook to initialize and return a constant value with stable identity. Unlike This is equivalent to setting a private member in a class constructor. | |
|
Hook to create a stable event handler that always calls the latest version of the callback. This hook solves the problem where event handlers need access to the latest props/state without causing unnecessary re-renders or re-registrations of event listeners. **Key Features**: - **Stable reference**: The returned callback has a stable identity that never changes - **Fresh values**: Always executes the latest version of the callback with current props/state - **Performance optimized**: Prevents re-renders in child components that depend on the callback - **Type safe**: Full TypeScript support with generic argument and return types - **React 19 compatible**: Uses useLayoutEffect for synchronous updates **When to use**: - Event handlers that depend on frequently changing props/state - Callbacks passed to memoized child components to prevent unnecessary re-renders - Event listeners attached to window, document, or long-lived DOM elements - Callbacks in useEffect dependencies that shouldn't trigger the effect on every change **Implementation Details**: - Uses | |
|
Hook to force update a function component by triggering a re-render. **⚠️ Performance Warning**: This hook will intentionally cause re-renders and should be used sparingly with clear intent. Overuse may introduce performance issues and long-running tasks. Consider using React's built-in state management patterns (useState, useReducer) or memoization strategies (useMemo, useCallback) before resorting to force updates. **🔧 Development Tools**: In development builds, this hook provides enhanced debugging features: - **Performance monitoring**: Tracks call frequency and warns about excessive usage - **Rapid call detection**: Alerts when multiple calls occur within a single frame (16ms) - **DevTools integration**: Displays call count in React DevTools for debugging - **Profiler marks**: Creates performance markers for React Profiler analysis - **Cleanup warnings**: Detects components with short lifetimes but many force updates This implementation uses | |
|
Hook to generate a stable unique ID for the component instance. This hook provides a consistent way to generate IDs for accessibility attributes and form elements. The generated ID is: - **Stable**: Never changes across renders for the same component instance - **Unique**: Guaranteed unique across all components using this hook - **Predictable**: Uses an optional prefix for easier debugging - **SSR-compatible**: Works correctly with server-side rendering **Use cases**: - Linking form labels to inputs via **React 18+ Alternative**: For React 18+, consider using the built-in | |
|
Hook to merge multiple refs into a single ref callback. When working with React refs, you often need to handle multiple refs on the same element: - Your own ref for component logic - A forwarded ref from a parent component - Refs from third-party libraries This hook merges all refs into a single callback ref that updates all of them. **Features**: - **Flexible input**: Accepts any combination of callback refs, ref objects, and null/undefined - **Type safe**: Full TypeScript support with proper type inference - **Performance optimized**: Memoizes the callback to prevent unnecessary re-renders - **Cleanup safe**: Properly cleans up all refs when the element unmounts - **SSR compatible**: Works correctly with server-side rendering | |
|
Hook to attach event listeners to window or document with automatic cleanup. This hook provides a declarative way to manage event listeners that: - **Automatically cleans up**: Removes listeners on unmount or when dependencies change - **Type safe**: Full TypeScript support for event types - **Performance optimized**: Uses stable callbacks to prevent re-registration - **SSR safe**: Handles server-side rendering gracefully - **Flexible target**: Supports window, document, or any event target **Common use cases**: - Window resize, scroll events - Document click/keydown for global interactions - Custom events on event targets - Keyboard shortcuts - Outside click detection | |
|
Hook to track and return the previous value of a prop or state. This hook captures and returns the value from the previous render, which is useful for: - **Comparison logic**: Detecting when a value has changed - **Animation triggers**: Starting animations when values change - **Effect optimization**: Avoiding unnecessary effects when values haven't changed - **Debugging**: Tracking value changes over time **Implementation Details**: - Uses | |
|
Hook to provide performance optimized timeout management with automatic cleanup. This hook provides a wrapper around |
Interfaces
|
Interface |
Description |
|---|---|
|
Interface for cancelable functions returned by debounce. Provides additional control over the debounced function execution. | |
|
Interface for event targets that support addEventListener and removeEventListener. | |
|
Updater callbacks returned by | |
Variables
|
Variable |
Description |
|---|---|
|
Lightweight alternative to FluentProvider for simple theme overrides. Use this instead of nesting FluentProvider when you only need theme changes. This component provides a minimal way to override theme tokens without the overhead of a full FluentProvider, making it ideal for performance-critical scenarios where only theme changes are needed. | |
|
A smart FluentProvider that automatically detects when it would be redundant and either warns in development or skips creating a provider in production. This helps prevent unnecessary provider nesting while maintaining the same API as the standard FluentProvider. | |
|
Hook that uses React throws a warning when using **When to use**: - Measuring DOM elements and updating state before paint - Synchronizing with external systems before browser paint - Reading layout information and causing a synchronous re-render - Any case where you need **When NOT to use**: - Most effects should use regular |
Type Aliases
|
Type Alias |
Description |
|---|---|
|
Event listener options that can be passed to addEventListener. | |
|
The timeout ID type that works across different environments | |