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-solid-components

v0.1.4

Published

These components will help you write modular code in dealing with maps, conditional rendering and if-else-if-else statements in your react applications. Happy coding 🎉 I would love to hear your feedback.

Downloads

4

Readme

React Solid Components

These components will help you write modular code in dealing with maps, conditional rendering and if-else-if-else statements in your react applications. Happy coding 🎉 I would love to hear your feedback.

This is an abstract of solid components of For, Show and Switch.

Content

  1. Installation
  2. Usage
    1. For component example
    2. Show component example
    3. Switch component example
  3. Demo

Installation

 npm i react-solid-components

Usage

Now, for all the examples we are going to use the following components MyComponent and Fallback.

export const MyComponent = props => {
  // This component receives a prop of name
  return (
    <div style={{ display: 'flex', alignItems: 'center', gap: 5 }}>
      <span
        style={{
          color: 'blueviolet',
          fontWeight: 'bold',
          fontSize: '1.1rem',
        }}
      >
        Name:
      </span>
      <span style={{ fontWeight: 'normal' }}>{props.name}</span>
    </div>
  );
};

export const Fallback = () => {
  return (
    <div>
      <h4
        style={{
          color: 'blueviolet',
          fontWeight: 'bold',
          fontSize: '1.1rem',
        }}
      >
        I am a fallback
      </h4>
    </div>
  );
};

For Component

This component handles control flow of mapping through arrays to be rendered.

import { For } from 'react-solid-components';

const ForExample = () => {
  // An array of names
  const names = ['Shahida', 'A-Rahman', 'Shareef', 'Ashraf', 'Marriam'];

  return (
    <div>
      <For each={names}>
        {(name, index) => <MyComponent key={index} name={name} />}
      </For>
    </div>
  );
};

export default ForExample;

Show Component

This component handles control flow of conditional rendering of a one way if-else statement.

import { Show } from 'react-solid-components';

const ShowExample = () => {
  // A name variable
  const name = 'Ashraf';

  return (
    <div>
      <Show when={name === 'Ashraf'} fallback={<Fallback />}>
        <MyComponent name={name} />
      </Show>
    </div>
  );
};

export default ShowExample;

Switch Component

This component handles control flow of conditional rendering of multi if-else-if-else statements and it goes together with Match component.

import { Switch, Match } from 'react-solid-components';

const SwitchExample = () => {
  // A name variable
  const name = 'Ashraf';

  // in this example the fourth component will be matched
  return (
    <div>
      <Switch fallback={<Fallback />}>
        <Match when={props.name === 'Shahida'}>
          <div>First match component</div>
        </Match>

        <Match when={props.name === 'A-Rahman'}>
          <div>Second match component</div>
        </Match>

        <Match when={props.name === 'Shareef'}>
          <div>Third match component</div>
        </Match>

        <Match when={props.name === 'Ashraf'}>
          <div>Fourth match component</div>
        </Match>

        <Match when={props.name === 'Marriam'}>
          <div>Fifth match component</div>
        </Match>
      </Switch>
    </div>
  );
};

export default ShowExample;

Demo

Checkout the StoryBook examples of the components Examples.