Skip to content

Instantly share code, notes, and snippets.

@walaura
Last active July 20, 2020 17:08
Show Gist options
  • Save walaura/032e3415786644932394fbe23da32fdb to your computer and use it in GitHub Desktop.
Save walaura/032e3415786644932394fbe23da32fdb to your computer and use it in GitHub Desktop.
this could be a useJquery() hook but u playin
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