Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

showing error for few seconds react

const [visible, setVisible] = useState(false)

useEffect(() => {
  // message is empty (meaning no errors). Adjust as needed
  if(!message){
    setIsVisible(false)
    return
  }
  // error exists. Display the message and hide after 5 secs
  setIsVisible(true)
  const timer = setTimeout(() => {
     setIsVisible(false)
  }, 5000);
  return () => clearTimeout(timer);
}, [message]) // executes every time `message` changes. Adjust as needed
 
PREVIOUS NEXT
Tagged: #showing #error #seconds #react
ADD COMMENT
Topic
Name
3+2 =