Skip to content

Commit 455e95e

Browse files
docs: troubleshooting page
1 parent b27e298 commit 455e95e

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed

docs/docs/troubleshooting.mdx

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
sidebar_position: 4
3+
---
4+
5+
# Troubleshooting
6+
7+
Some tips on how to solve common issues with ReactTooltip.
8+
9+
import { Tooltip } from 'react-tooltip'
10+
import 'react-tooltip/dist/react-tooltip.css'
11+
12+
export const TooltipAnchor = ({ children, id, ...rest }) => {
13+
return (
14+
<span
15+
id={id}
16+
style={{
17+
display: 'flex',
18+
justifyContent: 'center',
19+
margin: 'auto',
20+
alignItems: 'center',
21+
width: '60px',
22+
height: '60px',
23+
borderRadius: '60px',
24+
color: '#222',
25+
background: 'rgba(255, 255, 255, 1)',
26+
cursor: 'pointer',
27+
boxShadow: '3px 4px 3px rgba(0, 0, 0, 0.5)',
28+
border: '1px solid #333',
29+
}}
30+
{...rest}
31+
>
32+
{children}
33+
</span>
34+
)
35+
}
36+
37+
Before trying these, make sure you're running the latest ReactTooltip version with
38+
39+
```sh
40+
npm install react-tooltip@latest
41+
```
42+
43+
or
44+
45+
```sh
46+
yarn add react-tooltip@latest
47+
```
48+
49+
If you can't find your problem here, make sure there isn't [an open issue on GitHub](https://github.com/ReactTooltip/react-tooltip/issues) already covering it.
50+
If there isn't, feel free to [submit a new issue here](https://github.com/ReactTooltip/react-tooltip/issues/new/choose).
51+
52+
## Next.js `TypeError: f is not a function`
53+
54+
This problem seems to be caused by a bug related to the SWC bundler used by Next.js.
55+
The best way to solve this is to upgrade to `next@13.3.0` or later versions.
56+
57+
Less ideally, if you're unable to upgrade, you can set `swcMinify: false` on your `next.config.js` file.
58+
59+
## Bad performance
60+
61+
If you're experiencing any kind of unexpected behavior or bad performance on your application when using ReactTooltip, here are a few things you can try.
62+
63+
### Move `<Tooltip />` on the DOM
64+
65+
This is specially relevant when using components that are conditionally rendered.
66+
67+
Always try to keep the `<Tooltip />` component rendered, so if you're having issues with a tooltip you've placed inside a component which is placed/removed from the DOM dynamically, try to move the tooltip outside of it.
68+
69+
We usually recommend placing the tooltip component directly inside the root component of your application (usually on `App.jsx`/`App.tsx`). You can also move the `import 'react-tooltip/dist/react-tooltip.css'` there.
70+
71+
### Dynamically generated anchor elements
72+
73+
You should avoid needlessly using a large amount of `<Tooltip />` components. One tooltip component that you use across your whole application should be good enough in most cases, but you should be fine to add a few more if you need to use different styled tooltips.
74+
75+
Here's a simple example on how to improve performance when using dynamically generated items.
76+
Check the examples for the [`anchorSelect`](./examples/anchor-select) and [`render`](./examples/render) props for more complex use cases.
77+
78+
```jsx
79+
// ❌ BAD
80+
<div className="items-container">
81+
{
82+
myItems.map(({ id, content, tooltip }) => (
83+
<div
84+
key={id}
85+
className="item"
86+
data-tooltip-id={`tooltip-${id}`}
87+
>
88+
{content}
89+
<Tooltip id={`tooltip-${id}`} content={tooltip} />
90+
</div>
91+
))
92+
}
93+
</div>
94+
```
95+
96+
```jsx
97+
// ✅ GOOD
98+
<div className="items-container">
99+
{
100+
myItems.map(({ id, content, tooltip }) => (
101+
<div
102+
key={id}
103+
className="item"
104+
data-tooltip-id="my-tooltip"
105+
data-tooltip-content={tooltip}
106+
>
107+
{content}
108+
</div>
109+
))
110+
}
111+
</div>
112+
<Tooltip id="my-tooltip" />
113+
```

0 commit comments

Comments
 (0)