Im currently learning on tutorials of a project and they uses React Js for front end. This is my first time working on a react js so Im really confused on how to implement conditions of flipping:
'setShowAnimation' from true to false with a delay timer of 3 sec under the condition where 'setShowAnimation == true'. Any reference / guide is much appreciated!
const App = () => {
...
const [showAnimation, setShowAnimation] = useState(false);
...
const wave = async () => {
try {
.......
const waveTxn = await wavePortalContract.wave(tweetValue,{gasLimit:300000});
console.log("Mining...", waveTxn.hash);
setShowAnimation(true);
.....
}
React.useEffect(() => {
const timeout = setTimeout(() => {
setShowAnimation(false)
},3000)
return () => clearTimeout(timeout)
}, [showAnimation])
}
you have to add a condition if it needs to be run only when showAnimation is true.
React.useEffect(() => {
if(showAnimation){
const timeout = setTimeout(() => {
setShowAnimation(false)
},3000)
return () => clearTimeout(timeout)
}
}, [showAnimation])