From 97a73ee9559554cd7b75e9e822a0fdf8f0c0c52b Mon Sep 17 00:00:00 2001 From: Apostolos Christodoulou Date: Wed, 20 Dec 2023 22:39:28 +0000 Subject: [PATCH] fix play-on-mount --- package.json | 2 +- src/index.ts | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index ba255d8..057a482 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.ts b/src/index.ts index e1a42ab..9a030f1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 @@ -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 }; };