npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-global-loader

v1.2.4

Published

Simple Customizable Global React Loader

Downloads

797

Readme

React Global Loader

Simple Customizable Global React Loader. Demo page

Install

npm i react-global-loader

Simple Usage

Import LoaderContainer in App.js or root js

import { LoaderContainer } from "react-global-loader";

export default function App() {
  return (
    <div>
      <LoaderContainer />
    </div>
  );
}

Or LoaderContainer with default spinner component

import { LoaderContainer, DefaultSpinner } from "react-global-loader";

export default function App() {
  return (
    <div>
      <LoaderContainer>
        <DefaultSpinner />
      </LoaderContainer>
    </div>
  );
}

Or LoaderContainer with a image file

import { LoaderContainer } from "react-global-loader";
import FidgetLoader from "./loader.gif";

export default function App() {
  return (
    <div>
      <LoaderContainer>
        <img src={FidgetLoader} alt="loading" />
      </LoaderContainer>
    </div>
  );
}

Usage inside pages, components and services

import { loader } from "react-global-loader";

export default function PageName() {
  const showLoader = () => {
    loader.show();
  };

  const hideLoader = () => {
    loader.hide();
  };

  useEffect(() => {
    showLoader();

    setTimeout(() => {
      hideLoader();
    }, 3000);
  });

  return <div>Page 1</div>;
}

Extended Usage

import { LoaderContainer, loader } from "react-global-loader";

export default function App() {
  const showLoader = () => {
    loader.show();
  };

  const hideLoader = () => {
    loader.hide();
  };

  useEffect(() => {
    showLoader();

    setTimeout(() => {
      hideLoader();
    }, 3000);
  });

  const Arrow = () => (
    <div
      style={{
        width: 0,
        height: 0,
        borderTop: "10px solid transparent",
        borderRight: "20px solid red",
        borderBottom: "10px solid transparent",
      }}
    ></div>
  );

  return (
    <div>
      <LoaderContainer opacity={0.5} backgroundColor="#ccc">
        <div style={{ display: "inline-flex" }}>
          <Arrow />
          <div style={{ marginLeft: "10px" }}> Custom Loader</div>
        </div>
      </LoaderContainer>
    </div>
  );
}

Using with react-loader-spinner

If you are familiar with react-loader spinner please do check out the official page and npm page .

import { Audio } from "react-loader-spinner";
import { LoaderContainer, loader } from "react-global-loader";

export default function App() {
  useEffect(() => {
    loader.show();
    setTimeout(() => {
      loader.hide();
    }, 5000);
  });
  return (
    <LoaderContainer>
      <Audio
        height="100"
        width="100"
        color="#4fa94d"
        ariaLabel="audio-loading"
        wrapperStyle={{}}
        wrapperClass="wrapper-class"
        visible={true}
      />
    </LoaderContainer>
  );
}

Container Properties

| Property | Default Value | Type | Description | | --------------- | ------------- | ------- | ------------------------------------------------------------------------ | | opacity | 1 | number | Set Opacity level for overlay background | | backgroundColor | #0000003a | string | Set background color for overlay | | justify | center | string | Horizontal alignment of loader content (flex) | | align | center | string | Horizontal alignment of loader content (flex) | | defaultText | Loading.. | string | Default text for loader | | defaultShow | false | boolean | Set to true if you want to show by default | | id | rgl-overlay | string | HTML id value, if you want to have multiple type of loaders | | autoHide | false | boolean | If you want to automatically hide the loader after a certain time period | | hideDuration | 3000 | number | Increase or decrease the value if autoHide is enabled |

Loader Properties

| Property | Default Value | Type | Description | | -------- | ------------- | ------ | ----------------------------------------------------- | | id | rgl-overlay | string | Pass Id if multiple loader are there to hide and show |