I Created a Simple TodoList using react and tried to integrate GSAP into the project. Here I made use of the state to create controlled animation.
The Problem is
When I add a Todo to the List the Todo is getting added but the opacity of the element is set to 0.
Help me when am I going wrong.
Todo.js component
import React, { useRef, useEffect, useState } from "react";
import { useDispatch } from "react-redux";
import { ToggleTodo } from "../actions";
import {TimelineMax} from "gsap/all";
const Todo = ({ todoInfo }) => {
const dispatch = useDispatch();
let todoRef = useRef(null);
let [playState, setPlayState] = useState(true);
const tl = new TimelineMax({ paused: true });
useEffect(() => {
tl.fromTo(
todoRef,
1,
{ opacity: 0 },
{ opacity: 1, y: "10px", onComplete: () => setPlayState(false) }
);
if (playState) tl.play();
});
return (
<div
className={`alert mb-2 text-white todoItem ${
todoInfo.isCompleted ? "bg-success" : "bg-info"
}`}
onClick={() => dispatch(ToggleTodo(todoInfo.id))}
ref={element => {
todoRef = element;
}}
>
{todoInfo.todoText}
{todoInfo.isCompleted}
</div>
);
};
export default Todo;