Skip to content

Commit

Permalink
separated position logic from initialiser
Browse files Browse the repository at this point in the history
for increasing performance
  • Loading branch information
adnan-td committed Aug 29, 2023
1 parent 9cc5e40 commit be0b8ed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-mouse-follower",
"version": "1.1.6",
"version": "1.1.7",
"description": "React mouse follower is a package based on react and framer motion. It provides components to add and customise cool mouse follower to your cursor",
"repository": {
"type": "git",
Expand Down
18 changes: 9 additions & 9 deletions src/component/follower_init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import { FollowerDiv } from './follower_div.js';

export function FollowerInitialiserComponent({ options }: { options: MouseSettings }) {
const [isHovering, setIsHovering] = useState<boolean>(false);
const [pos, setPos] = useState<MousePosition>({
x: 0,
y: 0,
});

useEffect(() => {
const handleMouseLeave = () => {
Expand All @@ -29,6 +25,14 @@ export function FollowerInitialiserComponent({ options }: { options: MouseSettin
};
}, []);

return <PositionHandler options={options} show={isHovering && options.visible !== false} />;
}

function PositionHandler({ options, show }: { options: MouseSettings; show: boolean }) {
const [pos, setPos] = useState<MousePosition>({
x: 0,
y: 0,
});
useEffect(() => {
const mouseMove = (event: any) => {
setPos({
Expand All @@ -42,9 +46,5 @@ export function FollowerInitialiserComponent({ options }: { options: MouseSettin
};
}, [options?.radius]);

return (
<AnimatePresence mode="wait">
{isHovering && options.visible !== false ? <FollowerDiv options={options} pos={pos} /> : null}
</AnimatePresence>
);
return <AnimatePresence mode="wait">{show ? <FollowerDiv options={options} pos={pos} /> : null}</AnimatePresence>;
}

0 comments on commit be0b8ed

Please sign in to comment.