Skip to content

Commit

Permalink
fix play-on-mount
Browse files Browse the repository at this point in the history
  • Loading branch information
tol-is committed Dec 22, 2023
1 parent ed13599 commit 97a73ee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"randomizer",
"yugop"
],
"version": "2.2.12",
"version": "2.2.13",
"license": "MIT",
"module": "dist/use-scramble.esm.js",
"main": "dist/index.js",
Expand Down
25 changes: 13 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,18 +367,8 @@ export const useScramble = (props: UseScrambleProps) => {
* reset scramble when text input is changed
*/
useEffect(() => {
if (!controlRef.current.length && !playOnMount) {
stepRef.current = text.length;
scrambleIndexRef.current = text.length;
overdriveRef.current = text.length;
controlRef.current = text.split('');
} else {
reset();
}
return () => {
cancelAnimationFrame(rafRef.current);
};
}, [text, overdrive, overflow]);
reset();
}, [text]);

/**
* start or stop animation when text and speed change
Expand All @@ -394,5 +384,16 @@ export const useScramble = (props: UseScrambleProps) => {
};
}, [animate]);

useEffect(() => {
if (!playOnMount) {
controlRef.current = text.split('');
stepRef.current = text.length;
scrambleIndexRef.current = text.length;
overdriveRef.current = text.length;
draw();
cancelAnimationFrame(rafRef.current);
}
}, []);

return { ref: nodeRef, replay: play };
};

0 comments on commit 97a73ee

Please sign in to comment.