skip to Main Content

I am working on how to display warning message on react native and found console.warn and console.error works very well as per my requirement. but only issue is those alert box remains unless closed by user. can you guys suggest how to let those alert box disappear by itself automatically after passing 3 second.

Below is the default code to display console warning on screen

console.warn("This is a test warning");

and current warning on display shown as below and user need to click on cross sign to close this alert box , my request is how can I let it disappear automatically after ew second .

enter image description here

2

Answers


  1. If we look the purposes of console commands, they are not like UI things so you can not dismiss them afterwhile in right way. There is a big BUT here because you ignore all logs with LogBox.ignoreAllLogs.

    For Example:

     console.warn(
         "Hey! I am a warning."
     );
    
     setTimeout(() => {
         LogBox.ignoreAllLogs(true)
     }, 3000);
    

    This way is not too good. Do not use console for it because i know you are going to use warn again so you need ignoreAllLogs to false then you will see the same warning message in your screen. I do not think it is something.

    Login or Signup to reply.
  2. As said by @Engin. You are misusing the purpose of console.warn and most proabaly what you need is a snackbar feature that is available in Android native app development using java. So i would suggest you to try snackbar either from react native paper or use from npm .

    for more info in npm refer this link

    for more info on react native paper use this link

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search