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-repeat

v1.0.2

Published

A helper component to render a list of components from a datasource.

Downloads

8

Readme

react-render-repeat

carbon (37)

NPM JavaScript Style Guide

Install

npm install --save react-render-repeat

Usage

Import as "RenderRepeat" and use as illustrated in the examples below. There are many more powerful usages that may not be illustrated, so take a look at the source code to see what more you can do.

Props

list: Array: The datasource (array) from which to render components.

render: ({el: Object, index: Number, isFirst: Boolean, isSecondLast: Boolean, isLast: Boolean}) => Node: An arrow function to render a component for each element in the list.

isPlaceholder: (element) => Boolean: An arrow function that returns whether or not the current element should be rendered, treated as a placeholder.

renderPlaceholder: ({el: Object, index: Number, isFirst: Boolean, isSecondLast: Boolean, isLast: Boolean}) => Node: An arrow function that renders a component when isPlaceholder returns true for that element.

Examples

import React, { Component } from "react";

import RenderRepeat from "react-render-repeat";

class Example extends Component {
  render() {
    return (
      <div>
        <h1>Example uses</h1>

        <div>
          <h2>Example 1:</h2>
          <p>
            Provide the datasource as "list" and your render arrow function as
            "render".
          </p>
          <RenderRepeat
            list={[
              { id: "uA1", name: "User A" },
              { id: "uB2", name: "User B" },
              { id: "uC3", name: "User C" }
            ]}
            render={({ el, index, isLast }) => {
              return (
                <div>
                  <p>ID: {el.id}</p>
                  <p>Name: {el.name}</p>
                  {isLast ? (
                    <p>As index {index}, I'm the last in the list</p>
                  ) : null}
                </div>
              );
            }}
          />

          <div>
            <h3>🌴 The output of this example should be:</h3>

            <div>
              <p>ID: uA1</p>
              <p>Name: User A</p>
            </div>
            <div>
              <p>ID: uB2</p>
              <p>Name: User B</p>
            </div>
            <div>
              <p>ID: uC3</p>
              <p>Name: User C</p>
              <p>At index 2, I'm the last in the list</p>
            </div>
          </div>
        </div>

        <div>
          <h2>Example 2: Placeholders</h2>
          <p>
            When paginating your datasource from the server, you may want to
            show placeholders while you wait for the server's response of more
            items. RenderRepeat supports that case.
            <br />
            <br />
            To render placeholders, simply include placeholder elements in your datasource
            and provide two extra props: "isPlaceholder" and "renderPlaceholder";
            both must be arrow functions. "isPlaceholder" should return true if an
            element should be rendered as a placeholder by "renderPlaceholder".
            <br />
            <br />
            If "isPlaceholder" returns true for an element, that element will be
            rendered by "renderPlaceholder" instead of "render".
            <br />
            <br />
            Once your server responds with the real data, replace the placeholder
            elements with the real data. At that point, RenderRepeat will rerender
            your list with the new paginated data.
          </p>
          <RenderRepeat
            list={[
              { id: "uA1", name: "User A" },
              { id: "uB2", name: "User B" },
              { $isPlaceholder: true },
              { $isPlaceholder: true },
              { $isPlaceholder: true }
            ]}
            render={({ el, index, isLast }) => {
              return (
                <div key={el.id}>
                  <p>ID: {el.id}</p>
                  <p>Name: {el.name}</p>
                  {isLast ? (
                    <p>As index {index}, I'm the last in the list</p>
                  ) : null}
                </div>
              );
            }}
            isPlaceholder={({ $isPlaceholder }) => !!$isPlaceholder}
            renderPlaceholder={({ index }) => (
              <div key={`placeholder${index}`}>
                <p>I am the loading indicator at index {index} ... </p>
                <p>
                  I should be replaced after the real data returns from the
                  server.
                </p>
              </div>
            )}
          />

          <div>
            <h3>🌴 The output of this example should be:</h3>

            <div>
              <p>ID: uA1</p>
              <p>Name: User A</p>
            </div>
            <div>
              <p>ID: uB2</p>
              <p>Name: User B</p>
            </div>
            <div>
              <p>I am the loading indicator at index 2 ...</p>
              <p>
                I should be replaced after the real data returns from the
                server.
              </p>
            </div>
            <div>
              <p>I am the loading indicator at index 3 ...</p>
              <p>
                I should be replaced after the real data returns from the
                server.
              </p>
            </div>
            <div>
              <p>I am the loading indicator at index 4 ...</p>
              <p>
                I should be replaced after the real data returns from the
                server.
              </p>
            </div>
          </div>
        </div>
      </div>
    );
  }
}

License

By Lincoln W Daniel

MIT © Lwdthe1