Skip to content

docs(readme): add tip on rebuild for dynamic content relates to #469 #633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 46 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ yarn add react-tooltip

## Usage

**Using NPM**
### Using NPM

1 . Require react-tooltip after installation

Expand All @@ -55,11 +55,11 @@ import ReactTooltip from 'react-tooltip';

3 . Include react-tooltip component

```js
```jsx
<ReactTooltip />
```

**Standalone**
### Standalone

You can import `node_modules/react-tooltip/dist/index.js` into your page. Please make sure that you have already imported `react` and `react-dom` into your page.

Expand Down Expand Up @@ -107,7 +107,7 @@ Notes:

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-react](https://www.npmjs.com/package/sanitize-html-react). 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.

##### Note:
#### Note

1. **data-tip** is necessary, because `<ReactTooltip />` finds the tooltip via this attribute
2. **data-for** corresponds to the **id** of `<ReactTooltip />`
Expand All @@ -119,7 +119,7 @@ The `html` option allows a tooltip to directly display raw HTML. This is a secur

> Hide the tooltip manually, the target is optional, if no target passed in, all existing tooltips will be hidden

```js
```jsx
import ReactTooltip from 'react-tooltip'

<p ref={ref => this.fooRef = ref} data-tip='tooltip'></p>
Expand All @@ -135,7 +135,7 @@ import ReactTooltip from 'react-tooltip'

> Show specific tooltip manually, for example:

```js
```jsx
import ReactTooltip from 'react-tooltip'

<p ref={ref => this.fooRef = ref} data-tip='tooltip'></p>
Expand Down Expand Up @@ -172,6 +172,46 @@ Same for empty children, if you don't want show the tooltip when the children is
<ReactTooltip id='test'>{}</ReactTooltip>
```

### 3. Tooltip not binding to dynamic content

When you render `<ReactTooltip>` ahead of dynamic content, and are using `data-for={id}` attributes
on new dynamic content, the tooltip will not register its event listener.

For example, you render a generic tooltip in the root of your app, then load a list of content async.
Elements in the list use the `data-for={id}` attribute to bind the tooltip on hover.
Since the tooltip has already scanned for data-tip these new elements will not trigger.

One workaround for this is to trigger `ReactTooltip.rebuild()` after the data load to scan for the attribute again,
to allow event wireup.

#### Example

```jsx
<app>
<ReactTooltip id="foo" />
<list/>
</app>
```

```jsx

const dynamicList = (props) => {

useEffect(() => {
ReactTooltip.rebuild();
});

return(
<list>
{data.map((item)=> {
<span data-for="foo">My late bound tooltip triggered data</span>
});}
</list>
);
};

```

## Article

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