
In this post, we've learned about creating toast messages in React Native. So, create a free Waldo account here to test its features. After that, the test cases will be generated automatically, and our testing will be done automatically. We can then do user iteration like clicking on the button. With this platform, we just need to upload the APK or IPA file. To do this, we can use the no-code testing platform Waldo instead of writing all test cases manually.

However, adding the Toast.js component to the testing would require us to write a very complicated test case. 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.
