Vamsi
Vamsi

Reputation: 392

How to show a button after 10 seconds using react hooks

I am very new to React hooks can someone please help me how to show a button after 10 seconds I tried a little but I don't know how to implement it.

This is my code

import React, { useState, useEffect } from 'react';
import './App.css';

const App = () => {

  const [show, setShow] = useState(false)

  useEffect(() => {
  });


  return (
    <div className='container'>
      <div className='row'>
        <div className='col-12'>
          <div className='main'>
            <button className='btn btn-primary'>Click here</button>
          </div>
        </div>
      </div>
    </div>
  )
}

export default App

```

Upvotes: 1

Views: 1406

Answers (1)

Mayank Pandeyz
Mayank Pandeyz

Reputation: 26258

Try this:

useEffect(() => {
  setTimeout(() => setShow(true), 10000);
}, []);  []: this is important as it will run this effect only once on component load

and use it like:

{show && <button className='btn btn-primary'>Click here</button>}  // this will show the button when show state will be true

Upvotes: 5

Related Questions