Last active
June 13, 2019 18:36
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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