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-weather-illustrations

v1.3.0

Published

A react wrapper around @bybas/weather-icons that allows chunking of assets to aid with caching and reduce initial bundle size

Downloads

13

Readme

react-weather-illustrations

Demo app Bundle size Support semantic-release Conventional Commits

This is a react wrapper for the awesome weather icon library produced by Bas Milius. This library is rather large (2mb) so my wrapper uses dynamic imports to request the icon when you need it instead of adding the entire icon library to your initial bundle.

Usage

Currently this can be used with suspense, dynamic loading libraries such as react loadable or with a basic hook.

Promise

This is the basic loader for use with everything except React suspense. Currently there are two.

String Loader

import React, { useState, useEffect } from 'react';
import { loadSvgStringAsync } from 'react-weather-illustrations';

const Demo: React.FC = () => {
    const [icon, setIcon] = useState<string | undefined>();

    useEffect(() => {
        const getIcon = async () => {
            const data = await loadSvgStringAsync('darksky', 'fill', 'clear-day');
            setIcon(data);
        }

        getIcon();
    }, []);

    return icon 
        ? <img src={icon} alt="weather icon" /> 
        : <div>Loading...</div>;
}

JSX Loader

import React, { useState, useEffect } from 'react';
import { loadAsync } from 'react-weather-illustrations';

const Temperature: React.FC = () => {
    const [Icon, setIcon] = useState<JSX.Element | undefined>();

    useEffect(() => {
        const getIcon = async () => {
            const icon = await loadAsync('darksky', 'fill', 'clear-day');
            setIcon(icon);
        }

        getIcon();
    }, []);

    return Icon ? <Icon /> : <div>Loading...</div>;
}

Suspense

Because suspense is reliant on a different flow this library exports repositories which are essentially just fetchers that cache and throw the result.

import React, { Suspense } from 'react';
import { repositories } from 'react-weather-illustrations';

const Icon: React.FC = () => {
    const svg = repositories.fill.darksky.read('clear-night');
    return <img src={svg} alt="weather icon" />;
}

export const Temperature: React.FC = () => (
    <Suspense fallback={<div>Loading</div>}>
        <Icon />
    </Suspense>
)

Loadable

This is an example of how this library can be used with one of many third party loading tools.

import React from 'react';
import loadable from '@loadable/component';
import { loadSvgStringAsync } from 'react-weather-illustrations';

const loader = async () => {
  const icon = await loadSvgStringAsync('darksky', 'fill', 'clear-night');
  return {
    default: () => <img src={icon} alt="" />
  }
};

export const Temperature = loadable(loader, {
  fallback: <div>Loading...</div>,
})