React Haiku is a lightweight utility library offering a comprehensive collection of React Hooks and utility components designed to streamline development and enhance efficiency. Currently at version 2.4.1, the library maintains an active release cadence, frequently adding new hooks and improving existing ones, as evidenced by multiple minor releases and updates in recent months. Its primary goal is to provide developers with ready-to-use solutions for common React patterns, such as state management, DOM manipulation, and browser API interactions, thereby saving development time. Key differentiators include its focus on being a "clean & lightweight" collection, providing a wide array of specialized hooks like `useHover`, `useBatteryStatus`, `useCookie`, and utility components like `<For />` and `<Switch />`, all while shipping with TypeScript types for improved developer experience. It requires React version 16.8.0 or newer.
npm install react-haikuVerified import paths — ran on the pinned version, not inferred.
Demonstrates common usage patterns for `useHover`, `useTitle`, and `useCookie` hooks within a React component, showcasing state management and side effects.
Implement client-side only rendering for components utilizing browser-API-dependent hooks, or wrap their usage within `typeof window !== 'undefined'` checks. For Next.js, consider `dynamic(() => import('...'), { ssr: false })`.Wrap callback functions that are passed to `useEventListener`, `useInterval`, or similar hooks with `React.useCallback` to memoize them. This prevents unnecessary re-creations and ensures the hook's internal logic can correctly manage event listeners or timers.
Be aware of the strict typing when destructuring `useInputValue`. If mutable variables are needed, copy the values or explicitly cast them. For most usage patterns with input values, this `as const` assertion enhances type safety by preventing incorrect reassignments.
Ensure all calls to `react-haiku` hooks are made directly within the body of a React function component, or within another custom hook which itself is called from a function component.
Ensure that the `each` prop provided to the `<For />` component is always an array, even if empty. Initialize `list` variables with `[]` to prevent `undefined` values, e.g., `<For each={list || []} ... />`.Check for `null` values explicitly before using the returned cookie value, or provide a default fallback. For example: `const [value] = useCookie('my_cookie'); const displayValue = value ?? 'Default';`