Skip to content

Commit

Permalink
fix: use pauseRef.current to determine pause action
Browse files Browse the repository at this point in the history
  • Loading branch information
jason89521 committed Aug 14, 2022
1 parent 1ceff07 commit c1adce7
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/components/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ const Main = ({
loop = false,
pause = false,
}: TypistProps) => {
const [typedChildrenArray, setTypedChildrenArray] = useState<TypedChildren[]>([]);
const [typedChildrenArray, setTypedChildrenArray] = useState<TypedChildren[]>(
[]
);
const [currentIndex, setCurrentIndex] = useState(-1);
const clearTimerRef = useRef(emptyFunc);
const loopRef = useRef(loop);
Expand Down Expand Up @@ -88,18 +90,18 @@ const Main = ({
const actions = getActions(children, splitter);
if (startDelay > 0) await timeoutPromise(startDelay);
for (const { type, payload } of actions) {
if (pause) await pausePromise();
if (pauseRef.current) await pausePromise();
if (type === 'TYPE_TOKEN') {
setCurrentIndex(prev => prev + 1);
setCurrentIndex((prev) => prev + 1);
await timeoutPromise(typingDelay);
} else if (type === 'BACKSPACE') {
let amount = payload;
while (amount--) {
setCurrentIndex(prev => prev + 1);
setCurrentIndex((prev) => prev + 1);
await timeoutPromise(backspaceDelay);
}
} else if (type === 'PASTE') {
setCurrentIndex(prev => prev + 1);
setCurrentIndex((prev) => prev + 1);
} else if (type === 'DELAY') {
await timeoutPromise(payload);
}
Expand Down

0 comments on commit c1adce7

Please sign in to comment.