react-tooltip is a comprehensive and highly customizable React component for displaying tooltips. Currently at version 5.30.1, it boasts an active development cycle with frequent patch and minor releases that introduce new features, resolve bugs, and enhance performance. Built on `floating-ui`, it offers significant performance improvements over its predecessors and is written entirely in TypeScript, providing robust type definitions out-of-the-box. Key differentiators include extensive customization options via props and data attributes, support for various event triggers (e.g., hover, click), and built-in accessibility features like automatic `aria-describedby` generation. It requires React and ReactDOM versions 16.14.0 or higher as peer dependencies, ensuring compatibility with modern React applications.
npm install react-tooltipVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic hover and click triggered tooltips, along with programmatic control.
Update anchor elements to use the new `data-tooltip-` prefixed attributes (e.g., `data-tooltip-id` and `data-tooltip-content`). Refer to the v4->v5 changelog for a complete list.
Change your import statements from `import ReactTooltip from 'react-tooltip';` to `import { Tooltip } from 'react-tooltip';`.Remove all calls to `ReactTooltip.rebuild()`. The component now handles updates automatically. If issues arise, report them with a reproducible example.
Refactor content provision to use `data-tooltip-content` attribute on the anchor or the `content` prop directly on the `Tooltip` component.
If you require the `float` effect, explicitly set the `effect` prop to `float` on your `Tooltip` component: `<Tooltip effect="float" ... />`.
Ensure your bundler (e.g., Webpack) is correctly configured to handle `.mjs` files and ESM modules within `node_modules`. This may involve adding rules like `{ test: /\.mjs$/, include: /node_modules/, type: 'javascript/auto' }` to your Webpack configuration.For v5+, ensure you are using `import { Tooltip } from 'react-tooltip';`. If the error persists, check your bundler configuration for proper ESM handling (e.g., Webpack's `javascript/auto` for `.mjs` files). For v4, use `import ReactTooltip from 'react-tooltip';`.Verify that the `id` prop on `<Tooltip>` exactly matches the `data-tooltip-id` attribute on your interactive element. Also, ensure that `react-tooltip`'s default styles are being imported (e.g., `import 'react-tooltip/dist/react-tooltip.css';`).
Ensure you are on v5+ (which handles updates automatically). If on v4, call `ReactTooltip.rebuild()` after dynamic content changes. For v5, if automatic updates fail, ensure your anchor element is correctly rendered and its `data-tooltip-content` or `content` prop is bound to reactive state. Consider using the `setIsOpen` prop for explicit control in complex scenarios.
Ensure that the `ref` prop is correctly attached to the `Tooltip` component instance, e.g., `const tooltipRef = useRef<TooltipRef>(null); <Tooltip ref={tooltipRef} ... />`. Avoid manually trying to set the ref to a DOM element directly when the type expects a component ref.