Then, clear the interval by using clearInterval.įinally, in the onNewToast(), check if the duration is passed and set it to the timeOut variable. In the closeToast(), set the message to null and, again, set the timeOut variable to 4,000 milliseconds. If it becomes 0, which means it ran four times, we're calling the closeToast function. We've also made it equal to the timeOutRef varible declared earlier, each time reducing 1,000 milliseconds from the timeOut state variable. Here, we'll use the setInterval function to run every 1,000 milliseconds. It's required to create a ref because we'll use it at different places in our code. We've also created a ref with the name timeOutRef. Here, we'll use a new state variable called timeOut, which has an initial value of 4,000 milliseconds. So, let's add this feature in the Toast.js file. Our toast message will be shown continuously, but a toast message needs to disappear after some time.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |