【发布时间】:2021-09-02 14:26:30
【问题描述】:
我正在尝试获取一个使用 React.forwardRef 和 NextJS Link 的徽标,以便在悬停时更改为不同的图像并且仍然可以工作。
这在 CSS 中相当简单,但我被困在 NextJS / Tailwind 世界中如何做到这一点。
目前我正在使用hover: animate-pulse...
帮助表示赞赏!
import React from "react";
import Link from "next/link";
import Image from "next/image";
const MyLogo = React.forwardRef(({ onClick, href }, ref) => {
return (
<a href={href} onClick={onClick} ref={ref}>
<Image src="/logo1.png" width={88} height={77} alt="logo" />
</a>
);
});
export default function Nav() {
return (
<nav className="flex items-center justify-between flex-wrap bg-raisin-black p-6">
<div className="flex items-center flex-shrink-0 mr-6 cursor-pointer hover:animate-pulse">
<Link href="/">
<MyLogo />
</Link>
</div>
</nav>
);
}
【问题讨论】:
-
非常感谢@SeanW!这正是我需要阅读的内容,我现在正在使用 Hook 和 onMouseEnter() / onMouseLeave() 来完成此操作
标签: next.js tailwind-css