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 🙏

© 2026 – Pkg Stats / Ryan Hefner

general-component

v1.0.3

Published

General Component(GC, from now) is a React component generation library which helps you prototype your service quickly.

Readme

General Component

General Component(GC, from now) is a React component generation library which helps you prototype your service quickly.

With using this library, you don't need to write your components to build prototype. You can just use components before you write them! See below. Pay attention that there's no declaration of CP.Greeting component.

한국어를 사용하시나요? 여기 한국어 번역본이 있습니다.

import CP from "general-component";

function App() {
  const [message, setMessage] = useState<string>("");

  return (
    <div className="App">
      <CP.Greeting
        style={{width: "370px"}}
        title={"Hello, buddies!"}
        description={"Let me introduce my new progress of react development!"}
        tags={[
          {id: "1", body: "react"},
          {id: "2", body: "react native"},
          {id: "3", body: "open source"},
          {id: "4", body: "frontend"}
        ]}
        message={message}
        onMessageChange={setMessage}
        onReply={()=>alert("Danke! You replied with: " + message)}
      />
    </div>
  );
}

Example code result 1

Getting started

Install

The library is hosted on NPM repository. You can use the following commands to install GC.

npm i general-component

Basic usage

First, import CP, which is abbreviation of ComponentPool, to use this library. Use CP.YourComponentName pattern to pre-use your component.

You can render string, number and Date by the following code. Feel free to add more properties with different names so that you know how it works!

import CP from "general-component";

<CP.UserCard
  name={"John Doe"}
	  age={24}
  joinedAt={new Date()}
/>

Example code result 2

Creating button

You can create a button with passing a parameterless function.

<CP.UserCard
  name={"John Doe"}
  onClick={()=>alert("Hi!")}
/>

Example code result 3

Creating string and integer inputs

If you pass properties with onValueChange and value pair, they are combined into one editing component.

At this moment this behavior only works with string and integer types(not including float).

<CP.SignIn
  id={id}
  onIdChange={setId}
  password={password}
  onPasswordChange={setPassword}
  onSignIn={()=>alert("Signed in!")}
/>

Example code result 4

Handling array of data

You can insert sub-objects with the following code.

Remember, you are asked to pass key or id field. If you don't, React may complain about this.(Though it works)

<CP.SocialMediaFeed
  title={"Hi Doe"}
  body={"How's everything going?"}
  tags={[
    {id: "doe", name: "doe"},
    {id: "greeting", name: "greeting"},
    {id: "good", name: "feeling good"},
  ]}
/>

Example code result 5

Embedding custom children

When you pass children, they will be displayed right after auto-generated properties.

<CP.SocialMediaFeed
  title={"Hi Doe"}
>
  <CustomFeedBody feed={feed}/>
</CP.SocialMediaFeed>

Example code result 6

How unhandled properties are shown

When GC encounters with unexpected properties, it gives up to render it and renders only their names at the bottom.

<CP.HasUnknownProps
  title={"String can be read"}
  specialBody={{
    an_object: "zxcv",
    something: "asfd",
    special: "qwer",
  }}
/>

Example code result 7

Replacing with custom component

Okay, you done your prototyping and actual components should be placed.

Then you can simply assign your custom components to CP.

You can insert this code anywhere, but it's recommended to do this at the top of App.js file.

const CustomComponent = (p: {title: string}) => {
  const {title} = p;

  const style: Record<string, any> = {
    width: "140px",
    border: "2px dashed pink",
    padding: "8px",
  };
  return <div style={style}>This is a custom component! with title: {title}</div>;
};

CP.Post = CustomComponent;

function App() {
  return <CP.Post
    title={"The aliens conquered the White House"}
  />;
};

Example code result 8

Adding custom middleware

You can customize the library! You can let your special data types can be read by General Component.

There are three kinds of middlewares.

  • Entry transformation middleware
  • Field generation middleware
  • Component generation middleware

They can be customized with the following code.

Do not forget to prepend the existing middleware, unless you intended it.

import {
    entryTransMiddlewares,
    fieldGenMiddlewares,
    componentGenMiddlewares,
    
    setEntryTransMiddlewares,
    setFieldGenMiddlewares,
    setComponentGenMiddlewares,
} from "general-component";

setEntryTransMiddlewares([...entryTransMiddlewares, yourCustomMiddleware]);

Caveats

style, innerStyle, children, innerClassName and className properties will not processed like other properties.

style and className will be passed to root container of General Component. innerStyle and innerClassName will be passed to property components wrapper(for example, you can set display: flex or flex-direction: row in here).

children is rendered directly below the auto-generated components.

When to use it

  • When you want to concentrate on your logic. Just pass the whole data to General component, and leave implementing the actual components to others or you in the future.
  • When you have data API and don't know the schema. Just pass the whole JS object to General component! At least you can see which values are in there, and remove unnecessary fields.
function App() {
  const [callResult, setCallResult] = useState<any>();
  useEffect(
    ()=>{ axios("https://random-data-api.com/api/app/random_app").then(setCallResult); },
    []
  );

  // Just put your data! We'll handle extra!
  // You event don't need to know the data schema.
  return <CP.App {...callResult?.data}/>;
}

Example code result 9

Documents

On progress!(May be ready by 2021-08)

Contribute

You can contribute to the project in various ways.

  • Become a regular contributor and one of our team members
  • Resolve issues and fix bugs
  • GIve ideas, do feature requests and feedback
  • Donation

Please do not hesitate to send email to [email protected] if you want to contribute!

License

Licensed under the MIT License, Copyright © 2021-present by REED