Open VonPappen opened 6 months ago
Sorry for my late reply. I'm not exactly sure what kind of effect you want to achieve but if you want to trigger the flip with click instead of hover you can do something like this:
import { useRef, useState } from "react";
import { FlipTilt, FlipTiltRef } from "react-flip-tilt";
const front = "/images/01-front.webp";
const back = "/images/01-back.webp";
function App(): React.ReactNode {
const [isFlipped, setIsFlipped] = useState(true);
const ref = useRef<FlipTiltRef | null>(null);
const handleClick = () => {
if (!isFlipped) return;
setIsFlipped(false);
ref.current?.flip();
};
const handleMouseLeave = () => {
setIsFlipped(true);
};
return (
<main className="flex items-center justify-center p-8">
<FlipTilt
width={165}
borderRadius="16px"
ref={ref}
style={{ cursor: isFlipped ? "pointer" : undefined }}
disabledFilter=""
disabled={isFlipped}
onClick={handleClick}
onMouseLeave={handleMouseLeave}
front={front}
back={back}
/>
</main>
);
}
export default App;
Discussed in https://github.com/rashidshamloo/react-flip-tilt/discussions/2
}`
This is what I have so far. but the problem is that the flip animation gets triggered twice. Any Workaround?