braposo / react-text-loop

Animate words in your headings

Home Page:https://codesandbox.io/s/react-text-loop-playground-br4q1

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add optional onChange callback

dmytrotkk opened this issue · comments

It would be nice to have something like that for words change action:

textChange(textLoopState){
    // do something...
 }

<TextLoop onChange={textChange}>
    {wordsObj}
</TextLoop>

My proposal:

// TextLoop.jsx
 tick = () => {
        this.setState((state, props) => {
+            if(this.props.onChange){
+              this.props.onChange(state);
+            }

             ...

        });
 };

Hi @Dmitry-Tk, sorry for the delay but it seems like a sensible proposal. I've been making some improvements to the library, but just didn't have the time to put everything together and make a new release.

I'll definitely add this to the API, but if you want to contribute please feel free to open a PR!

onChange callback is now supported on v2.0.0