Skip to content

Instantly share code, notes, and snippets.

@rockerBOO
Last active June 13, 2019 18:36
Show Gist options
  • Save rockerBOO/fe6f5d04cd801ec22aef1256ed36f9f5 to your computer and use it in GitHub Desktop.
Save rockerBOO/fe6f5d04cd801ec22aef1256ed36f9f5 to your computer and use it in GitHub Desktop.
Trying to manage instances and ref in React with Tippy without creating new react components.
import React from 'react'
import useTippy from './useTippy.js'
const Example = () => {
const [tippyInstance, tippyElementRef] = useTippy({content: 'Test'})
return <div>
<span ref={tippyElementRef}>Tippy</span>
</div>
}
import { useState, useCallback } from 'react'
import tippy from 'tippy.js'
const useTippy = options => {
const [instance, setInstance] = useState(null)
const ref = useCallback(
node => {
if (node !== null) {
setInstance(tippy(node, options))
}
},
[options]
)
return [instance, ref]
}
export default useTippy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment