I have a React app that does 3 things; displays the elements in an array, adds an element on button press and removes an element on button press.
Inside of my image, I am displaying my local .gif file. My .gif file is a single animation .gif, I turned off infinite looping because I want the .gif to spawn in and then remain static.
My error comes when I add a second .gif element to my array. Only the first element displays its animation and the rest display the final slide in the .gif.
I believe that I may be able to solve my issue if I manage to instantiate the element but I am not sure how I would go about doing that.
Here is an excerpt from my code::
function App(){
const [numbValue, numbUpdate] = useState(0);
const [starsValue, starsUpdate] = useState(null);
function DisplayGIF(numbToDisp){
let value=[];
for(let i=0;i<numbToDisp;i++){
value.push(<img className="icon" src={process.env.PUBLIC_URL + "/once-star-filled.gif"} alt="animated star"/>)
}
starsUpdate(<>{value.map(element=>{return element;})}</>);
}
function Add(){
numbUpdate(numbValue+1);
DisplayGIF(numbValue+1);
}
function Sub(){
numbUpdate(numbValue-1);
DisplayGIF(numbValue-1);
}
return(<>
<p onClick={Add}>+</p>
{starsValue}
<p onClick={Sub}>-</p>
</>);
}
Output:: First add :: displays 1 image that is animated until the end Consecutive adds :: displays x images that display the final frame in the animation