Skip to content

Commit c51f037

Browse files
docs: readme troubleshooting section
1 parent 455e95e commit c51f037

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

README.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,86 @@ import ReactDOMServer from 'react-dom/server';
153153
</a>
154154
```
155155

156+
## Troubleshooting
157+
158+
Before trying these, make sure you're running the latest ReactTooltip version with
159+
160+
```sh
161+
npm install react-tooltip@latest
162+
```
163+
164+
or
165+
166+
```sh
167+
yarn add react-tooltip@latest
168+
```
169+
170+
If you can't find your problem here, make sure there isn't [an open issue](https://github.com/ReactTooltip/react-tooltip/issues) already covering it.
171+
If there isn't, feel free to [submit a new issue](https://github.com/ReactTooltip/react-tooltip/issues/new/choose).
172+
173+
### Next.js `TypeError: f is not a function`
174+
175+
This problem seems to be caused by a bug related to the SWC bundler used by Next.js.
176+
The best way to solve this is to upgrade to `next@13.3.0` or later versions.
177+
178+
Less ideally, if you're unable to upgrade, you can set `swcMinify: false` on your `next.config.js` file.
179+
180+
### Bad performance
181+
182+
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.
183+
184+
#### Move `<Tooltip />` on the DOM
185+
186+
This is specially relevant when using components that are conditionally rendered.
187+
188+
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.
189+
190+
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.
191+
192+
#### Dynamically generated anchor elements
193+
194+
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.
195+
196+
Here's a simple example on how to improve performance when using dynamically generated items.
197+
Check the docs for examples for the [`anchorSelect`](https://react-tooltip.com/docs/examples/anchor-select) and [`render`](https://react-tooltip.com/docs/examples/render) props for more complex use cases.
198+
199+
```jsx
200+
// ❌ BAD
201+
<div className="items-container">
202+
{
203+
myItems.map(({ id, content, tooltip }) => (
204+
<div
205+
key={id}
206+
className="item"
207+
data-tooltip-id={`tooltip-${id}`}
208+
>
209+
{content}
210+
<Tooltip id={`tooltip-${id}`} content={tooltip} />
211+
</div>
212+
))
213+
}
214+
</div>
215+
```
216+
217+
```jsx
218+
// ✅ GOOD
219+
<div className="items-container">
220+
{
221+
myItems.map(({ id, content, tooltip }) => (
222+
<div
223+
key={id}
224+
className="item"
225+
data-tooltip-id="my-tooltip"
226+
data-tooltip-content={tooltip}
227+
>
228+
{content}
229+
</div>
230+
))
231+
}
232+
</div>
233+
<Tooltip id="my-tooltip" />
234+
```
235+
156236
## Article
157237

158238
[How I insert sass into react component](https://medium.com/@wwayne_me/how-i-insert-sass-into-my-npm-react-component-b46b9811c226#.gi4hxu44a)

0 commit comments

Comments
 (0)