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-render-fam

v1.0.11

Published

Lit components for conditional rendering, Fam

Downloads

20

Readme

react-render-fam

PRs Welcome

A family of 🔥 components to make conditional rendering in React kool again.

preview

Installation

npm: $ npm install --save react-render-fam

or

Yarn: $ yarn add react-render-fam

Usage

<If>

Conditionally renders the children nodes when the predicate(s) return true.

Props:

  • predicate A boolean expression

Example:

import { If } from 'react-render-fam';

function shouldISayHello() {
    return true;
}

<If predicate={shouldISayHello()}>
    <p>Hello World!</p>
</If>

<Omit>

Renders a subset of elements which return truthy for all supplied predicates.

Props:

  • predicates A function or an array of functions. Current value is passed to each predicate for evaluation
  • values An array of elements to be evaluated and rendered
  • render Called for every value that satisfies the supplied predicates

Example: Renders all values between 6 and 99

import { Omit } from 'react-render-fam';

const data = [
    { id: 2, value: 1 },
    { id: 3, value: 10 },
    { id: 4, value: 20 },
    { id: 5, value: 99 },
    { id: 7, value: 2000 },
];

const greaterThanFive = ({ value }) => value > 5;
const lessThanOneHundred = ({ value }) => value < 100;

<Omit
    values={data}
    predicates={[
        greaterThanFive,
        lessThanOneHundred,
    ]}
    render={({ id, value }) => (
        <p key={id}>{value}</p>
    )}
/>

<Sort>

Sorts the elements in the order specified by the supplied comparison function. Internally uses Array.prototype.sort() to determine the correct order of elements.

Defaults to ascending order if compare or descending props are omitted.

Props:

  • by The key which is evaluated when comparing values
  • compare A user supplied comparison function. For more information on using compare please see: Array.prototype.sort()
  • descending When supplied orders the elements in defending order (Assuming the comparison value is an integer or string)
  • values An array of objects to be compared and rendered
  • render A function used to render each sorted element

Example: Renders the list of names in alphabetical order

import { Sort } from 'react-render-fam';

const data = [
    { name: 'Edward', id: 1 },
    { name: 'Sharpe', id: 2 },
    { name: 'And', id: 3 },
    { name: 'The', id: 4 },
    { name: 'Magnetic', id: 5 },
    { name: 'Zeros', id: 6 },
];

const compare = (by, a, b) => {
    const nameA = a[by].toUpperCase();
    const nameB = b[by].toUpperCase();

    if (nameA < nameB) {
        return -1;
    }

    if (nameA > nameB) {
        return 1;
    }

    return 0;
};

<Sort
    values={data}
    by="name"
    compare={compare}
    render={({ id, name }) => (
        <p key={id}>{name}</p>
    )}
/>

License

MIT © Daniel Del Core