Question: I am new to React.js. I am not sure how to add `delay` to render in React.js. What is the best way to add delay.

I am adding the following code in render but its not working.

```
setTimeout(function() {

}, 1000);

```

Answer: 
**Pure typescript Solution**

You would be able to create delay function with `async`:

```
function timeout(delay: number) {
    return new Promise( res => setTimeout(res, delay) );
}

```

And then call the function:

```
await timeout(1000); //for 1 sec delay

```
With React hooks. It will wait `5s` and then render this component.

```
import React from 'react'

const DeleayComponent = () => {
  const [show, setShow] = React.useState(false)

  React.useEffect(() => {
    const timeout = setTimeout(() => {
      setShow(true)
    }, 5000)

    return () => clearTimeout(timeout)

  }, [show])

  if (!show) return null

  return <>OK, Render</>
}

export default DeleayComponent

```