A super-lightweight, dependency-free React tooltip component optimized for high-performance applications with hundreds of tooltips. You can visit https://react-tooltip.pages.dev/ for the documentation and examples.
- ✅ Zero Dependencies - Only requires React
- ✅ No External CSS - Styles injected via singleton pattern
- ✅ Highly Optimized - Designed for 500+ tooltips on a single page
- ✅ Minified Bundle - ~400 bytes of CSS, minified class names
- ✅ TypeScript Support - Fully typed with TypeScript
- ✅ Customizable - Flexible props for positioning, timing, and styling
- ✅ Production Ready - Battle-tested performance optimizations
npm install @gozenc/react-tooltip
# or
yarn add @gozenc/react-tooltip
# or
pnpm add @gozenc/react-tooltipimport Tooltip from "@gozenc/react-tooltip";
function App() {
return (
<Tooltip content="Hello World!" position="top">
<button>Hover me</button>
</Tooltip>
);
}| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
content |
string |
✅ Yes | - | The text to display in the tooltip |
position |
"top" | "right" | "bottom" | "left" |
No | "top" |
Position of the tooltip relative to the wrapped element |
className |
string |
No | "" |
Custom CSS class for the wrapper element |
offset |
number |
No | 8 |
Distance between tooltip and element (in pixels) |
delay |
number |
No | 200 |
Hover delay before showing tooltip (in milliseconds) |
<Tooltip content="Click to submit">
<button>Submit</button>
</Tooltip><Tooltip content="User settings" position="right">
<IconButton icon="settings" />
</Tooltip><Tooltip content="Quick action" offset={12} delay={100}>
<button>Action</button>
</Tooltip><Tooltip content="Styled tooltip" className="my-custom-wrapper">
<span>Hover me</span>
</Tooltip>The component uses a singleton pattern to inject CSS styles only once, regardless of how many tooltip instances exist on the page. This means:
- With 500 tooltips: Only 1
<style>tag in the DOM (not 500!) - Styles are injected when the module loads
- Zero overhead for additional tooltip instances
Event handlers are wrapped with useCallback to maintain stable references:
handleMouseEnter- Memoized withdelaydependencyhandleMouseLeave- Memoized with no dependenciescalculatePosition- Memoized withpositionandoffsetdependencies
The CSS is fully minified with:
- No whitespace or newlines
- Shortened property values (e.g.,
0.2s→.2s) - Single-line format
- Result: ~650 bytes (46% reduction from original)
The tooltip position is calculated dynamically based on:
- Wrapper element dimensions
- Tooltip content dimensions
- Selected position (top/right/bottom/left)
- Custom offset value
This ensures the tooltip is always properly positioned relative to its trigger element.
Arrows are positioned using CSS transforms and dynamically generated class names:
- Top position: Arrow points down from bottom of tooltip
- Bottom position: Arrow points up from top of tooltip
- Left position: Arrow points right from right side of tooltip
- Right position: Arrow points left from left side of tooltip
- Chrome/Edge (latest)
- Firefox (latest)
- Safari (latest)
- Any browser supporting ES6+ and React 16.8+
- 2.5KB (minified)
- 1.08KB (gzipped)
GTT stands for "Gozenc Tooltip" - emphasizing the singleton style injection pattern that makes this component efficient for global use across large applications.
- No inline styles: All styling uses CSS classes for better performance and easier customization
- Function declarations: Used instead of arrow functions for better readability and debugging
- Minimal API: Only essential props to keep the component simple and focused
- No external CSS files: Styles are injected programmatically to avoid import requirements
- Dynamic positioning only: Only
topandleftcoordinates use inline styles (unavoidable for dynamic positioning)
Potential features for future versions:
- Theme customization (colors, sizes)
- Animation options
- Multi-line content support
- HTML content support
- Portal rendering option
- Accessibility improvements (ARIA attributes)
- Touch device support
- Max-width configuration
Contributions are welcome! Please ensure:
- All optimizations are maintained
- No external dependencies are added
- TypeScript types are properly defined
- Performance benchmarks show no regression
MIT
Created for high-performance React applications requiring hundreds of tooltips without performance degradation.
