DEV Community

Dhiman_aman
Dhiman_aman

Posted on

How to add Loading Effect in ReactJS

Installing-
npm i react-spinners

https://www.davidhu.io/react-spinners/

In the App.js File

import React, { useEffect, useState } from "react";
import { HashLoader } from "react-spinners";


const Example6 = () => {
  const [load, setload] = useState(false);

  useEffect(() => {
    setload(true);
    setTimeout(() => {
      setload(false);
    }, 7000);
  }, []);

    const styleCSS = {
        display: "Flex",
        justifyContent :"center"
    }


  return (
    <>
          {load ? (

              <HashLoader color={"red"} loading={load} size={100} style={styleCSS} />
      ) : (
        <center>
          <h1> Try to make a loading </h1>
        </center>
      )}
    </>
  );
};

export default Example6;

Enter fullscreen mode Exit fullscreen mode

Top comments (0)