braposo / react-text-loop

Animate words in your headings
https://codesandbox.io/s/react-text-loop-playground-br4q1
MIT License
880 stars 66 forks source link

Fix issues with timeout #43

Closed kenime closed 4 years ago

kenime commented 4 years ago

@braposo Greeting! let me know if you need any further description on this PR.

braposo commented 4 years ago

Hi @kenime! Thanks for creating the PR!

Could you please describe in more detail what kind of issues are you referring to? I think your changes look sensible, but just want to understand exactly what are you fixing with this.

Thanks!

kenime commented 4 years ago

@braposo I was trying to pause the text loop by updating the interval to 0, but then I found that the timeout cannot be cleared such that the text loop will still go to the next child and then stopped.

By including this PR, the timeout will be cleared as expected, such that the text loop will immediately stop when interval is changed to 0.

The reason is that with animationframe, the loop function will update the requestId value after it is returned to caller, hence we need to create an object to hold the requestId and return the reference to object instead of directly return as value.

kenime commented 4 years ago

bump

braposo commented 4 years ago

sorry for the delay @kenime! All sounds quite sensible, thanks for taking the time to explain and fix the issue! Going to merge and release it as a new version!

braposo commented 4 years ago

This is now included in https://github.com/braposo/react-text-loop/releases/tag/v2.3.0