Skip to content
This repository was archived by the owner on Nov 9, 2024. It is now read-only.

Commit 0fae719

Browse files
committed
Update README to resolve #49
1 parent 4663e04 commit 0fae719

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

README.md

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,50 @@ Required props: tooltip content as `props.content` and a single element child
1919

2020
```jsx
2121
import React from 'react'
22-
import ReactDOM from 'react-dom'
2322
import Tippy from '@tippy.js/react'
2423

25-
const RegularTooltip = () => (
24+
const StringContent = () => (
2625
<Tippy content="Hello">
2726
<button>My button</button>
2827
</Tippy>
2928
)
3029

31-
const TooltipWithJSX = () => (
30+
const JSXContent = () => (
3231
<Tippy content={<span>Tooltip</span>}>
3332
<button>My button</button>
3433
</Tippy>
3534
)
3635

37-
const TooltipWithProps = () => (
36+
const VariousProps = () => (
3837
<Tippy content="Hi" arrow={true} duration={500} delay={[100, 50]}>
3938
<button>My button</button>
4039
</Tippy>
4140
)
41+
```
4242

43-
const App = () => (
44-
<main>
45-
<RegularTooltip />
46-
<TooltipWithJSX />
47-
<TooltipWithProps />
48-
</main>
49-
)
43+
## Component children
44+
45+
If you want to use a component as a child, ensure you forward the ref to the DOM
46+
node:
47+
48+
```jsx
49+
import React, { forwardRef } from 'react'
50+
51+
function ThisWontWork() {
52+
return <button>Text</button>
53+
}
5054

51-
ReactDOM.render(<App />, document.getElementById('root'))
55+
const ThisWillWork = forwardRef((props, ref) => {
56+
return <button ref={ref}>Text</button>
57+
})
58+
59+
function App() {
60+
return (
61+
<Tippy content="Tooltip">
62+
<ThisWillWork />
63+
</Tippy>
64+
)
65+
}
5266
```
5367

5468
## Native props
@@ -93,9 +107,6 @@ function App() {
93107
> **Note 1**: You should also set the `hideOnClick` prop to `false` if you don't
94108
> want the tippy to hide when the user clicks on the document somewhere.
95109
96-
> **Note 2**: Use this prop instead of Tippy's native `showOnInit` prop. The
97-
> native prop just shows the tippy on init but won't respond to prop changes.
98-
99110
### `onCreate?: (tip: Instance) => void`
100111

101112
Callback invoked when the Tippy instance has been created. Use this when you

0 commit comments

Comments
 (0)