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

@web-deps/react-logical-components

v0.1.1

Published

A JavaScript/TypeScript component library for handling JSX logic in React. The library increases code readability.

Downloads

1

Readme

react-logical-components

A component library used to handle common JSX logic like conditional rendering and mapping data to elements in React. The library increases code readability by replacing common logic like short circuit evaluation and ternary operators with components. The components can also be used for responsive and/or adaptive design; certain elements can be shown only on particular screen sizes.

Installation

NPM

npm i @web-deps/react-logical-components

Yarn

yarn add @web-deps/react-logical-components

Components

Empty

Empty renders an empty fragment. It can be used as a placeholder for components. You can use it when a component is required but you have not created the appropriate component yet.

<Empty />

Maybe

Maybe is used to display an element if a particular condition is met. If the condition has not been met, an empty fragment is displayed instead. This can be used as an alternative to short circuit evaluation. The code snippet below shows how Maybe can be used to toggle an alert element for a form.

<Maybe display={true}>
  <span>Form submission failed. Please try again</span>
</Maybe>

Either

Either is used to display one of two elements depending on a condition. If the condition is met, one of the elements is displayed. If the condition is not met, the other element is displayed. The component can be used as an alternative to a ternary operator. Below is an example of how Either can be used to display a loader while content is being fetched, and upon fetching, display content.

<Either displayFirst={true}>
  <span className="loader"></span>
  <main className="content">Main content</main>
</Either>

Any

Any can be used to display one of many elements. An index is provided to the component, and the element at that index is displayed. The code snippet below shows how Any can be used in a Tabs component.

<Any display={0}>
  <div className="tabs-tab">Tab 1 content</div>
  <div className="tabs-tab">Tab 2 content</div>
  <div className="tabs-tab">Tab 3 content</div>
</Any>

Some

Some is used to display one or more elements out of a group of elements. The elements to be displayed are specified through an array of indices of those elements. The order of the indices matters. This means that the elements will be displayed in the order specified by in the array. This makes it possible to reorder elements on different screen sizes or according to some other condition.

<Some display={[0, 1]}>
  <section>Section 1</section>
  <section>Section 2</section>
  <section>Section 3</section>
</Some>

ForEach

ForEach is used to map data to elements. This is ideal for lists, tables, select menus and the like. The code snippet below shows how to use ForEach to display a list of items.

<ul>
  <ForEach
    data={["Item 1", "Item 2", "Item 3"]}
    renderComponent={(item, index) => <li key={String(index)}>{item}</li>}
  />
</ul>

License

MIT License.