Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Cannot read property 'error' of null at AnimationItem.triggerEvent #25

Open
chapster11 opened this issue Jul 31, 2020 · 1 comment

Comments

@chapster11
Copy link

I'm getting this error when trying to call a goToAndPlay method on the animationRef element.

Uncaught TypeError: Cannot read property 'error' of null
    at AnimationItem.triggerEvent (lottie.js:236)
    at AnimationItem.triggerRenderFrameError

Based on the blow code the errors goes away if I remove my set state call in eventHandler.
setPath(collection[index]);
Obviously I need that to keep my queue loop going of new loottie files.
Anyone might know why this error is happening ?

const LottieCollection = ({ status}) => {
  const ref = useRef<AnimationItem>(null) as React.MutableRefObject<
    AnimationItem
  >;
  const queueStatus = useRef(status);
  const queue= [data1, data2];
  const [path, setPath] = useState<string[]>(queue[0]);
  const [state, setState] = useState<ReactLottiePlayingState>("paused");

  useEffect(() => {
    if (status === "goTo") {
      queueStatus .current = status;
      ref.current.goToAndPlay(0, true);
    }
  }, [status]);

  const eventHandler= (event: { type: string }) => {
    if (event.type === "complete") {
      if (queueStatus .current === "start") {
        console.log("loop");
        index = (index + 1) % 2;
        setPath(collection[index]);
      }
    }
  };

  return (
      <Lottie
        animationRef={ref}
        config={{
          animationData: path,
        }}
        playingState={state}
        lottieEventListeners={[{ name: "complete", callback: eventHandler}]}
      />
  );
};

Also do we really need to add the below work around to fix the animationRef typescript warning you get when you don't add this.`

useRef<AnimationItem>(null) as React.MutableRefObject<
    AnimationItem
  >;

@chapster11
Copy link
Author

chapster11 commented Jul 31, 2020

It looks like because i'm using a queue to update the lottie animationData after each animation completes, i'm seeing that the currentFrame of ref only updates for the first lottie animation after that it stops updating. It would seem the ref is old and not getting update internally ? Which might have something to do with why its throwing errors like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant