Last active
July 20, 2020 17:08
-
-
Save walaura/032e3415786644932394fbe23da32fdb to your computer and use it in GitHub Desktop.
this could be a useJquery() hook but u playin
This file contains 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
const Box = () => { | |
const ref = useJquery(($element) => { | |
$element.click(() => { | |
$element.animate( | |
{ | |
opacity: 0.25, | |
left: '+=50', | |
height: 'toggle', | |
}, | |
5000 | |
); | |
}); | |
}); | |
return ( | |
<div> | |
<button ref={ref}>Click me</button> | |
</div> | |
); | |
}; | |
const useJquery = (callback, deps = []) => { | |
const ref = useRef(); | |
useEffect(() => { | |
$.ready(() => { | |
/* | |
callback with jq object and jq | |
itself just in case | |
*/ | |
callback($(ref.current), $); | |
}, deps); | |
}); | |
return ref; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment