Skip to content

Commit bcfdb4f

Browse files
committed
docs: update readme.md to be more simple and update troubleshooting section on docs
1 parent ed2a4e6 commit bcfdb4f

File tree

2 files changed

+31
-186
lines changed

2 files changed

+31
-186
lines changed

README.md

Lines changed: 9 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020

2121
If you like the project, please give the project a GitHub 🌟
2222

23+
---
24+
25+
Why do we use ADS on our docs?
26+
27+
- ReactTooltip is an open source project, this is the way that we find to be financed by the community.
28+
2329
## Demo
2430

2531
[![Edit ReactTooltip](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/still-monad-yfi4fn?fontsize=14&hidenavigation=1&theme=dark)
@@ -42,121 +48,6 @@ Documentation for V5 - [ReactTooltip](https://react-tooltip.com/docs/getting-sta
4248
</a>
4349
</p>
4450

45-
## Installation
46-
47-
```sh
48-
npm install react-tooltip
49-
```
50-
51-
or
52-
53-
```sh
54-
yarn add react-tooltip
55-
```
56-
57-
## Usage
58-
59-
> :warning: ReactTooltip will inject the default styles into the page by default on version `5.13.0` or newer.
60-
> The `react-tooltip/dist/react-tooltip.css` file is only for style reference and doesn't need to be imported manually anymore if you are already using `v5.13.0` or upper.
61-
62-
> :warning: If you were already using `react-tooltip<=5.7.5`, you'll be getting some deprecation warnings regarding the `anchorId` prop and some other features.
63-
> In versions >=5.8.0, we've introduced the `data-tooltip-id` attribute, and the `anchorSelect` prop, which are our recommended methods of using the tooltip moving forward. Check [the docs](https://react-tooltip.com/docs/getting-started) for more details.
64-
65-
### Using NPM package
66-
67-
1 . Import the CSS file to set default styling.
68-
69-
> :warning: If you are using a version before than `v5.13.0`, you must import the CSS file or the tooltip won't show!
70-
71-
```js
72-
import 'react-tooltip/dist/react-tooltip.css'
73-
```
74-
75-
This needs to be done only once and only if you are using a version before than `5.13.0`. We suggest you do it on your `src/index.js` or equivalent file.
76-
77-
2 . Import `react-tooltip` after installation.
78-
79-
```js
80-
import { Tooltip } from 'react-tooltip'
81-
```
82-
83-
or if you want to still use the name ReactTooltip as V4:
84-
85-
```js
86-
import { Tooltip as ReactTooltip } from 'react-tooltip'
87-
```
88-
89-
3 . Add `data-tooltip-id="<tooltip id>"` and `data-tooltip-content="<your placeholder>"` to your element.
90-
91-
> `data-tooltip-id` is the equivalent of V4's `data-for`.
92-
93-
```jsx
94-
<a data-tooltip-id="my-tooltip" data-tooltip-content="Hello world!">
95-
◕‿‿◕
96-
</a>
97-
```
98-
99-
4 . Include the `<Tooltip />` element.
100-
101-
> Don't forget to set the id, it won't work without it!
102-
103-
```jsx
104-
<Tooltip id="my-tooltip" />
105-
```
106-
107-
#### Using multiple anchor elements
108-
109-
You can also set the `anchorSelect` tooltip prop to use the tooltip with multiple anchor elements without having to set `data-tooltip-id` on each of them.
110-
`anchorSelect` must be a valid [CSS selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors).
111-
112-
```jsx
113-
<a className="my-anchor-element" data-tooltip-content="Hello world!">
114-
◕‿‿◕
115-
</a>
116-
<a className="my-anchor-element" data-tooltip-content="Hello to you too!">
117-
◕‿‿◕
118-
</a>
119-
<Tooltip anchorSelect=".my-anchor-element" />
120-
```
121-
122-
Check [the V5 docs](https://react-tooltip.com/docs/getting-started) for more complex use cases.
123-
124-
### Standalone
125-
126-
You can import `node_modules/react-tooltip/dist/react-tooltip.[mode].js` into your page. Please make sure that you have already imported `react` and `react-dom` into your page.
127-
128-
mode: `esm` `cjs` `umd`
129-
130-
If you are using a version older than `v5.13.0` don't forget to import the CSS file from `node_modules/react-tooltip/dist/react-tooltip.css` to set default styling. This needs to be done only once in your application. Version `v5.13.0` or newer already inject the default styles into the page by default.
131-
132-
PS: all the files have a minified version and a non-minified version.
133-
134-
![image](https://user-images.githubusercontent.com/9615850/205637814-c0ef01ae-bd77-4e7f-b4bf-df502c71e5c3.png)
135-
136-
## Options
137-
138-
For all available options, please check [React Tooltip Options](https://react-tooltip.com/docs/options)
139-
140-
### Security note
141-
142-
The `html` option allows a tooltip to directly display raw HTML. This is a security risk if any of that content is supplied by the user. Any user-supplied content must be sanitized, using a package like [sanitize-html](https://www.npmjs.com/package/sanitize-html). We chose not to include sanitization after discovering it [increased our package size](https://github.com/wwayne/react-tooltip/issues/429) too much - we don't want to penalize people who don't use the `html` option.
143-
144-
#### JSX note
145-
146-
You can use [`renderToStaticMarkup()` function](https://reactjs.org/docs/react-dom-server.html#rendertostaticmarkup) to use JSX instead of HTML.
147-
**Example:**
148-
149-
```jsx
150-
import ReactDOMServer from 'react-dom/server';
151-
[...]
152-
<a
153-
data-tooltip-id="my-tooltip"
154-
data-tooltip-html={ReactDOMServer.renderToStaticMarkup(<div>I am <b>JSX</b> content</div>)}
155-
>
156-
◕‿‿◕
157-
</a>
158-
```
159-
16051
## Troubleshooting
16152

16253
Before trying these, make sure you're running the latest ReactTooltip version with
@@ -171,79 +62,11 @@ or
17162
yarn add react-tooltip@latest
17263
```
17364

65+
Please check our [troubleshooting section](https://react-tooltip.com/docs/troubleshooting) on our docs.
66+
17467
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.
17568
If there isn't, feel free to [submit a new issue](https://github.com/ReactTooltip/react-tooltip/issues/new/choose).
17669

177-
### The tooltip is broken/not showing up
178-
179-
Make sure you've imported the default styling. You only need to do this once on your application and only if you are using a version before `5.13.0`, `App.jsx`/`App.tsx` is usually a good place to do it.
180-
181-
```jsx
182-
import 'react-tooltip/dist/react-tooltip.css'
183-
```
184-
185-
If you've imported the default styling and the tooltip is still not showing up when you hover on your anchor element, make sure you have content to be displayed by the tooltip.
186-
187-
If `data-tooltip-content` and `data-tooltip-html` are both unset (or they have empty values) on the anchor element, and also the `content`, `render`, and `children` props on the tooltip are unset (or have empty values), the tooltip is not shown by default.
188-
189-
### Next.js `TypeError: f is not a function`
190-
191-
This problem seems to be caused by a bug related to the SWC bundler used by Next.js.
192-
The best way to solve this is to upgrade to `next@13.3.0` or later versions.
193-
194-
Less ideally, if you're unable to upgrade, you can set `swcMinify: false` on your `next.config.js` file.
195-
196-
### Bad performance
197-
198-
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.
199-
200-
#### Move `<Tooltip />` on the DOM
201-
202-
This is specially relevant when using components that are conditionally rendered.
203-
204-
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.
205-
206-
We usually recommend placing the tooltip component directly inside the root component of your application (usually on `App.jsx`/`App.tsx`).
207-
208-
#### Dynamically generated anchor elements
209-
210-
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.
211-
212-
Here's a simple example on how to improve performance when using dynamically generated items.
213-
214-
> 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.
215-
216-
```jsx
217-
// ❌ BAD
218-
<div className="items-container">
219-
{myItems.map(({ id, content, tooltip }) => (
220-
<div key={id} className="item" data-tooltip-id={`tooltip-${id}`}>
221-
{content}
222-
<Tooltip id={`tooltip-${id}`} content={tooltip} />
223-
</div>
224-
))}
225-
</div>
226-
```
227-
228-
```jsx
229-
// ✅ GOOD
230-
<div className="items-container">
231-
{
232-
myItems.map(({ id, content, tooltip }) => (
233-
<div
234-
key={id}
235-
className="item"
236-
data-tooltip-id="my-tooltip"
237-
data-tooltip-content={tooltip}
238-
>
239-
{content}
240-
</div>
241-
))
242-
}
243-
</div>
244-
<Tooltip id="my-tooltip" />
245-
```
246-
24770
## Article
24871

24972
[How I insert sass into react component](https://medium.com/@wwayne_me/how-i-insert-sass-into-my-npm-react-component-b46b9811c226#.gi4hxu44a)
@@ -270,7 +93,7 @@ We would gladly accept a new maintainer to help out!
27093

27194
## Contributing
27295

273-
We welcome your contribution! Fork the repo, make some changes, submit a pull-request! Our [contributing](contributing.md) doc has some details.
96+
We welcome your contribution! Fork the repo, make some changes, submit a pull-request! Our [contributing](CONTRIBUTION.md) doc has some details.
27497

27598
## License
27699

docs/docs/examples/html.mdx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,25 @@ import { Tooltip } from 'react-tooltip';
8484
id="my-tooltip-html-prop"
8585
html="Hello<br /><s>multiline</s><br /><b>HTML</b><br />tooltip"
8686
/>
87+
88+
#### Security note
89+
90+
The `html` option allows a tooltip to directly display raw HTML. This is a security risk if any of that content is supplied by the user.
91+
Any user-supplied content must be sanitized, using a package like [sanitize-html](https://www.npmjs.com/package/sanitize-html).
92+
We chose not to include sanitization after discovering it [increased our package size](https://github.com/wwayne/react-tooltip/issues/429) too much - we don't want to penalize people who don't use the `html` option.
93+
94+
#### JSX note
95+
96+
You can use [`renderToStaticMarkup()` function](https://reactjs.org/docs/react-dom-server.html#rendertostaticmarkup) to use JSX instead of HTML.
97+
**Example:**
98+
99+
```jsx
100+
import ReactDOMServer from 'react-dom/server';
101+
[...]
102+
<a
103+
data-tooltip-id="my-tooltip"
104+
data-tooltip-html={ReactDOMServer.renderToStaticMarkup(<div>I am <b>JSX</b> content</div>)}
105+
>
106+
◕‿‿◕
107+
</a>
108+
```

0 commit comments

Comments
 (0)