import React, { useState, useEffect } from 'react';
import { motion } from 'framer-motion';
export default function CustomCursor() {
const [position, setPosition] = useState<{ x: number; y: number }>({ x: 0, y: 0 });
useEffect(() => {
const handleMouseMove = (e: MouseEvent) => {
setPosition({ x: e.clientX, y: e.clientY });
};
// Add event listener for mouse movement
window.addEventListener('mousemove', handleMouseMove);
// Cleanup event listener on component unmount
return () => {
window.removeEventListener('mousemove', handleMouseMove);
};
}, []);
return (
<>
<motion.div
className="fixed top-0 left-0 w-4 h-4 bg-black rounded-full pointer-events-none z-50"
animate={{
x: position.x - 8,
y: position.y - 8,
}}
transition={{
type: 'spring',
stiffness: 500,
damping: 30,
}}
/>
</>
);
}
This CustomCursor component creates a custom cursor using Next.js, Tailwind CSS, and Framer Motion. It tracks the mouse position and moves a black circle smoothly following the cursor.