Skip to content

nDriaDev/react-tools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

329 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

@ndriadev/react-tools

๐ŸŽฏ The Ultimate React Toolkit

115+ Production-Ready Hooks โ€ข 9 Smart Components โ€ข 25+ Utilities โ€ข Full TypeScript

npm version bundle size downloads license TypeScript

๐Ÿ“š Documentation โ€ข ๐ŸŽฎ Live Demos โ€ข ๐Ÿ› Report Bug โ€ข โœจ Request Feature


โœจ Why React Tools?

๐ŸŽจ Developer Experience

  • ๐Ÿ’Ž TypeScript-first with complete type safety
  • ๐ŸŽฏ Intuitive APIs that feel natural
  • ๐Ÿ“– Rich documentation with live examples
  • ๐Ÿ” IntelliSense everywhere

โšก Performance

  • ๐ŸŒณ Tree-shakeable - import only what you need
  • ๐Ÿ“ฆ Tiny bundles - optimized for production
  • ๐Ÿš€ Zero dependencies (except React)
  • โš™๏ธ Optimized re-renders

๐Ÿ› ๏ธ Battle-Tested

  • โœ… Production-ready hooks and components
  • ๐Ÿงช Thoroughly tested patterns
  • ๐Ÿ”’ Type-safe implementations
  • ๐Ÿ“ฑ Cross-platform compatible

๐ŸŽ Feature-Rich

  • ๐ŸŽฃ 115+ hooks across 5 categories
  • ๐Ÿงฉ 9 components for common patterns
  • ๐Ÿ”ง 25+ utilities for everyday tasks
  • ๐ŸŒ Modern Web APIs integrated

๐Ÿš€ Quick Start

Installation

# npm
npm install @ndriadev/react-tools

# pnpm (recommended)
pnpm add @ndriadev/react-tools

# yarn
yarn add @ndriadev/react-tools

Basic Usage

import { useLocalStorageState, useDebounce, useWebSocket } from '@ndriadev/react-tools'

function App() {
  // Persistent state with localStorage sync
  const [theme, setTheme] = useLocalStorageState('theme', 'dark')

  // Debounced search with automatic cleanup
  const [search, setSearch] = useState('')
  const debouncedSearch = useDebounce(search, 500)

  // WebSocket with auto-reconnect and type-safety
  const ws = useWebSocket<MessageType>({
    url: 'wss://api.example.com',
    reconnect: { attempts: 5, exponentialBackoff: true },
    onMessage: (data) => console.log('Received:', data)
  })

  return <div>Your app here</div>
}

Tree-Shakeable Imports

Import only what you need for optimal bundle size:

// โœ… Import entire library (tree-shakeable)
import { useState History, useWebSocket } from '@ndriadev/react-tools'

// โœ… Import by category
import { useStateHistory } from '@ndriadev/react-tools/hooks/state'
import { useWebSocket } from '@ndriadev/react-tools/hooks/api-dom'

// โœ… Import components separately
import { SwitchCase, ErrorBoundary } from '@ndriadev/react-tools/components'

// โœ… Import utilities
import { isDeepEqual, mergeObjects } from '@ndriadev/react-tools/utils'

๐Ÿ“ฆ What's Inside?

๐ŸŽฃ Hooks (115+)

๐Ÿ—‚๏ธ State Management (17 hooks)

Advanced state management with history, validation, and persistence:

Hook Description
useStateHistory useState with undo/redo and time-travel
useReducerHistory useReducer with history tracking
useLocalStorageState Sync state with localStorage
useSessionStorageState Sync state with sessionStorage
useProxyState Deep reactive state with Proxy
useStateValidator State with built-in validation
useDerivedState Computed state from props
usePrevious Track previous value
useArray Array manipulation utilities
useMap Map state management
useSet Set state management
createPubSubStore Global pub/sub state
// Example: Undo/Redo functionality
const [count, setCount, { undo, redo, canUndo, canRedo }] = useStateHistory(0, 10)

<button onClick={() => setCount(c => c + 1)}>Increment</button>
<button onClick={undo} disabled={!canUndo}>Undo</button>
<button onClick={redo} disabled={!canRedo}>Redo</button>
โ™ป๏ธ Lifecycle (12 hooks)

Enhanced lifecycle hooks with custom comparison and abort control:

  • useEffectOnce - Run effect only once
  • useEffectCompare - Custom dependency comparison
  • useEffectDeepCompare - Deep equality check
  • useEffectAbortable - Built-in AbortController
  • useLayoutEffect* variants
  • useIsMounted - Check mount status
  • useLogger - Debug lifecycle changes
// Example: Deep comparison for objects
useEffectDeepCompare(() => {
  fetchData(filters) // Only runs when filters deeply change
}, [filters])
โšก Performance (8 hooks)

Optimize your components with smart memoization:

  • useMemoizedFn - Stable function references
  • useMemoCompare / useCallbackCompare - Custom comparison
  • useLazyRef - Lazy initialization
  • useMergedRef - Merge multiple refs
  • useId - Unique IDs (React 18 polyfill)
// Example: Stable callback without dependencies
const handleClick = useMemoizedFn((id) => {
  // Always has access to latest state
  // But reference never changes
  console.log('Clicked:', id, latestState)
})
๐Ÿ‘† Events (25 hooks)

Handle user interactions and DOM events efficiently:

Mouse & Touch:

  • useClickOutside - Detect clicks outside element
  • useHover - Hover state
  • useDoubleClick - Distinguish single/double click
  • useLongPress - Long press detection
  • useSwipe - Swipe gestures
  • usePinchZoom - Pinch-to-zoom

Observers:

  • useIntersectionObserver - Visibility detection
  • useResizeObserver - Element size changes
  • useMutationObserver - DOM mutations

Keyboard & Actions:

  • useHotKeys - Keyboard shortcuts
  • usePerformAction - Action delegation pattern
  • useEventListener - Generic event handling

Network & System:

  • useIsOnline - Online/offline status
  • useNetwork - Network information
  • useBeforeUnload - Prevent page close
// Example: Click outside to close
const ref = useClickOutside(() => setIsOpen(false))
<div ref={ref}>{isOpen && <Dropdown />}</div>
๐ŸŒ Web APIs (50+ hooks)

Modern browser APIs made easy:

Media:

  • useAudio / useVideo - Media element control
  • useMediaDevices - Camera/microphone access
  • useDisplayMedia - Screen sharing
  • usePIP - Picture-in-Picture
  • useSpeechRecognition / useSpeechSynthesis

Communication:

  • useWebSocket - WebSocket with reconnection
  • useWebWorker - Multi-threading
  • useFetch - Fetch with abort & caching
  • useEventSource - Server-Sent Events
  • useBroadcastChannel - Cross-tab messaging

Device & Sensors:

  • useBattery - Battery status
  • useGeolocation - GPS location
  • useDeviceOrientation / useDeviceMotion
  • useVibrate - Haptic feedback

UI & UX:

  • useFullscreen - Fullscreen mode
  • useClipboard - Clipboard operations
  • useColorScheme - Dark/light mode
  • useShare - Web Share API
  • useEyeDropper - Color picker
// Example: WebSocket with auto-reconnect
const ws = useWebSocket({
  url: 'wss://api.example.com',
  reconnect: {
    attempts: 5,
    exponentialBackoff: true
  },
  parser: 'json',
  onMessage: (data) => updateUI(data)
})

ws.sendJSON({ type: 'ping' })

๐Ÿงฉ Components (9)

Conditional Rendering:

// Show/Hide with fallback
<Show when={isLoggedIn} fallback={<Login />}>
  <Dashboard />
</Show>

// Switch-case logic
<SwitchCase.Switch>
  <SwitchCase.Case when={status === 'loading'}>
    <Spinner />
  </SwitchCase.Case>
  <SwitchCase.Case when={status === 'error'}>
    <Error />
  </SwitchCase.Case>
</SwitchCase.Switch>

List Rendering:

// Optimized list rendering
<For each={items} fallback={<EmptyState />}>
  {(item, index) => <ItemCard key={item.id} {...item} />}
</For>

Error Handling:

// Error boundary with reset
<ErrorBoundary
  fallback={(error, reset) => (
    <ErrorDisplay error={error} onReset={reset} />
  )}
  onError={(error) => logToService(error)}
>
  <App />
</ErrorBoundary>

Lazy Loading:

// Advanced lazy loading with retry
<LazyComponent
  loader={() => import('./HeavyComponent')}
  loading={<Skeleton />}
  error={(retry) => <ErrorWithRetry onRetry={retry} />}
/>

๐Ÿ”ง Utilities (25+)

Type Guards:

  • isDeepEqual / isShallowEqual - Equality checks
  • isMouseEvent / isTouchEvent - Event type guards
  • isAsync - Async function detection
  • isClient - SSR detection

Object & Array:

  • mergeObjects - Deep merge
  • getObjectFromDottedString - Path access ("user.profile.name")
  • uniqueElementsArray - Remove duplicates
  • alphanumericCompare - Natural sorting

String:

  • changeStringCase - Convert between cases
  • detectBrowser - Browser detection

DOM:

  • clickElementOnKeydownEvent - Accessibility helper
  • hotKeyHandler - Keyboard shortcuts
  • getBase64 - File conversion

Patterns:

  • PublishSubscribePattern - Pub/Sub implementation
  • EventsPattern - Event emitter
  • lazy - Lazy function execution

๐Ÿ“Š Browser Support

Browser Version
Chrome โ‰ฅ 90
Firefox โ‰ฅ 88
Safari โ‰ฅ 14
Edge โ‰ฅ 90

React Compatibility: React โ‰ฅ 16.8.0 (Hooks support required)


๐ŸŽฏ Use Cases

๐Ÿ“ฑ Modern Web Apps

Perfect for SPAs with complex state management and real-time features

๐Ÿข Enterprise Applications

Battle-tested patterns for large-scale applications with strict requirements

๐Ÿš€ Rapid Prototyping

Skip boilerplate and focus on features with ready-to-use hooks


๐Ÿ“ Changelog

See CHANGELOG.md for release history and breaking changes.

๐Ÿ“„ License

MIT ยฉ nDriaDev


๐Ÿ“ž Support


If you find Futurable useful, please consider giving it a โญ on GitHub!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages