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

v5.2.1

Published

Semantic helper components for rendering content with React.

Downloads

15

Readme

Install

Using npm:

$ npm install --save react-semantic-render

Using yarn:

$ yarn add react-semantic-render

Usage

Show

Renders content if when equals true.

| Property | Type | Description | | ---------- | -------- | ----------------------------- | | when | boolean | Conditional statement | | render | function | Shorthand for primary content | | children | node | Primary content |

import { Show } from "react-semantic-render";

<Show when={true}>
  <button>click me!</button>
</Show>;

Use the render prop when you dont want your content evaluated unless a condition is true

import { Show } from "react-semantic-render";

<Show when={!!label} render={() => <button>{label}</button>} />;

List

Renders content from specified callback function from either render or children on each element of items.

| Property | Type | Description | | ---------- | -------- | ----------------------------- | | items | any[] | Array to map | | render | function | Shorthand for primary content | | children | node | Primary content |

import { List } from "react-semantic-render";

<List items={["Jack", "Jane", "Joe"]}>{name => <span>{name}</span>}</List>;

Switch

Renders content from first Switch.Case that matches value, else Switch.Default if it exists.

| Property | Type | Description | | ---------- | ------- | --------------------- | | value | boolean | Conditional statement | | children | node | Primary content |

import { Switch } from "react-semantic-render";

<Switch value={3}>
  <Switch.Case value={3}>
    <span>Render me!</span>
  </Switch.Case>
  <Switch.Default>
    <button>Click me!</button>
  </Switch.Default>
</Switch>;

Why

In the example below you see two very common use cases where you have to render something when a condition is true and render content from an array of data. This is usually solved with inline arrow functions that are hard to read and easily becomes unmanageable in more complex components.

const App = ({ isLoading, results }) => (
    {results.length > 0 ? (
      <ul>
        {result.map(user => (
          <li key={user.id}>
            <span>{user.name}</span>
          </li>
        ))}
      </ul>
    ) : null}
);

Here you see how the component above could be rewritten with components from react-semantic-render. While it is abit more verbose, the readability is greatly increased and you immeadiatly see whats going on.

import { List, Switch } from "react-semantic-render";

const App = ({ isLoading, results }) => (
  <Show when={results.length > 0}>
    <ul>
      <List items={results}>
        {user => (
          <li key={user.id}>
            <span>{user.name}</span>
          </li>
        )}
      </List>
    </ul>
  </Show>
);

The purpose of this library is to provide helpful semantic render components that makes the React.Component render method easier to read and follow.

Do you have an idea about a component you think belong here? Tell us here!

Development

Install dependencies
$ yarn install
Run tests
$ yarn test

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style.

Commit style guide

We use conventional commits style. Read up on it before doing your first commit. Don't worry about making mistakes, commitlint will stop you and you can try again.

License

MIT