MCPcopy Create free account
hub / github.com/ReactTooltip/react-tooltip / ImperativeTooltipExample

Function ImperativeTooltipExample

src/test/tooltip-imperative.spec.js:12–37  ·  view source on GitHub ↗
({ onAfterShow, onAfterHide })

Source from the content-addressed store, hash-verified

10// Component that uses imperative API
11
12const ImperativeTooltipExample = ({ onAfterShow, onAfterHide }) => {
13 const tooltipRef = useRef(null)
14
15 const handleOpen = () => {
16 tooltipRef.current?.open()
17 }
18
19 const handleClose = () => {
20 tooltipRef.current?.close()
21 }
22
23 return (
24 <>
25 <button onClick={handleOpen}>Open Tooltip</button>
26 <button onClick={handleClose}>Close Tooltip</button>
27 <span data-tooltip-id="imperative-tooltip">Target Element</span>
28 <Tooltip
29 id="imperative-tooltip"
30 content="Imperative Tooltip"
31 ref={tooltipRef}
32 afterShow={onAfterShow}
33 afterHide={onAfterHide}
34 />
35 </>
36 )
37}
38
39describe('tooltip imperative API', () => {
40 test('tooltip can be opened and closed imperatively', async () => {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected