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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-greenify

v1.0.2

Published

Example React Component tutorial

Readme

React Greenify example Component package.

This is a simple example react Component and tutorial on how to make it.

First we create our package folder "react-greenify", and run yarn init to set things up.

mkdir -p react-greenify
cd react-greenify
yarn init

Answer the questions the best you can (ENTER, ENTER, ENTER!! haha).

Now we add the react dependency. Because it's a React Component.

yarn add react

Yarn package manager has a development only packages. So we add a the BabelJs transpiler.

yarn add --dev @babel/cli @babel/preset-react

Pack with Webpack

Webpack is in charge of taking your Js/CSS/images/data and transforming it into a bundle which can be used in development and in production.

First we get the webpack dependencies for development.

yarn add --dev webpack-cli webpack babel-loader

Now, we add a webpack.config.js.

{
  "name": "react-greenify",
  "version": "1.0.0",
  "description": "Example React Component tutorial",
  "main": "build/index.js",
  "repository": "https://github.com/illume/react-greenify",
  "author": "René Dudfield",
  "license": "MIT",
  "scripts": {
    "test": "jest",
    "start": "webpack --watch --mode=development",
    "build": "webpack --mode=production"
  },
  "dependencies": {
    "react": "^16.11.0",
    "webpack": "^4.41.2"
  },
  "devDependencies": {
    "@babel/cli": "^7.7.0",
    "@babel/plugin-proposal-object-rest-spread": "^7.6.2",
    "@babel/plugin-transform-react-jsx": "^7.7.0",
    "@babel/preset-env": "^7.7.1",
    "@babel/preset-react": "^7.7.0",
    "babel-jest": "^24.9.0",
    "babel-loader": "^8.0.6",
    "jest": "^24.9.0",
    "react-test-renderer": "^16.11.0",
    "webpack-cli": "^3.3.10"
  }
}

Then we add a couple of nice things for .babelrc.

yarn add --dev @babel/plugin-proposal-object-rest-spread @babel/plugin-transform-react-jsx

Webpack it, do the build.

yarn build

This generates the build/index.js file.

See how in the webpack.config.js there is a "main": "build/index.js",? This means your package points to the build/index.js file that webpack creates.

Test with Jest

See the Testing React Apps with jest docs for more.

yarn add --dev jest babel-jest @babel/preset-env @babel/preset-react react-test-renderer

Now we have to set up a test file, which we put in a "/__tests__" folder.

Name the test file after the component.test.js.

__tests__/ReactGreenify.test.js

import React from 'react';
import ReactGreenify from '../src/index.js';
import renderer from 'react-test-renderer';

it('renders correctly', () => {
  const tree = renderer
    .create(<ReactGreenify>Halo!</ReactGreenify>)
    .toJSON();
  expect(tree).toMatchSnapshot();
});

Do the test! (with jest)

yarn test

This will compare the snapshot in __tests__/__snapshots__ with what is rendered.

Hopefully it renders correctly.

development mode

What about in development mode?

yarn start

Will run "webpack --watch --mode=development" which watches for changes, and builds.

How to use the package in an app?

First let's "link" our react-greenify package.

This "symlinks" a package folder during development. So your app can use your package in development, and when things change in your package they'll get updated in your app too.

This way you don't have to do lots of releases just to test little things.

yarn link

See the yarn link documentation for more info.

Let's create an app!

Let's create a react app and use our react-greenify package in it.

npx create-react-app ourapp
cd ourapp
yarn link react-greenify

Now import the ReactGreenify inside the app, and use it.

import ReactGreenify from "react-greenify";

        <ReactGreenify>
          <p>meow meow meow!</p>
        </ReactGreenify>

To see our Component within the app, start the app up.

yarn start

You should be able to see your ReactGreenify in your web browser.

Publishing ReactGreenify

You'll first need a npmjs account from: https://www.npmjs.com/signup.

yarn login
yarn publish

Happy hacking!