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: 
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

```
One way to use hook with setTimeout is to set a property after the interval.

```
import { useState, useEffect } from "react";

const BotResponse = () => {

......

const [botMessage, setBotMessage] = useState('');

// function called from some user interaction
const botResponse = (msg) => {
   setTimeout(function() {
      setBotMessage(msg);
   }, 500);
};

useEffect(() => {
    console.log("bot msg... " + botMessage);

    // display the bot message

}, [botMessage]); // listening to a change on this property
}

```