Skip to main content

Command Palette

Search for a command to run...

Hello world!

How to make delay hooks in React

Published
1 min readView as Markdown
Hello world!
D

I am a Developer!

import React from "react";

export const HelloWorld = () => {
  const [content, setContent] = React.useState('')
  React.useEffect(() => {
    let mounted = true
    if (mounted) {
      setContent("Hello world! I'm only here for fun.")
      return () => {
        setTimeout(setContent, 5000, `Goodbye world! Thanks for readings!`)
        mounted = false
      }
    }
  }, [])
  return <code>{content}</code>
}

export default HelloWorld;