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-code-producer

v0.0.5

Published

An npm package to generate React code snippets for Component, functions etc.

Downloads

6

Readme

react-code-producer

npm   NPM   npm   npm bundle size

An npm package to generate React code snippets for Component, functions etc.

Table of contents

Generate code at terminal &

  • copy and use it to quickly test what you learned (beginners)

  • use in projects or other developement environment if your editor/IDE does have any plugins etc. (professionals)

  • Other usages e.g. to test functionality in scripts etc. (beginners, professionals)

    As I have shown here, how I directly copied the Box component and pasted directly above ReactDOM.render(...) statement.

    The thing is, before copy paste work, you have to configure settings at Codepen.

    Just setup you Babel transpiler, add React libraries and then try as shown in the below image.

Box At Codepen

Note

  • React uses different style to add comments among JSX code. So please write code after
{ 
    /* Add elements here */ 
    
}

React comment statement, not just inside the curly braces while using the copied in your React application.

  • npm install react-code-producer --save

    Installs locally

  • npm install react-code-producer --global

    Installs globally

Code code.js

const ReactCodeProducer = require("react-code-producer")

let App = new ReactCodeProducer()

console.log(App.getComponentCode('App'))

Output node code.js

import React from 'react';
import ReactDOM from 'react-dom';

// React Component class `App`
class App extends React.Component {
    render() {
        return (
            <div className="App">
                { 
                    /* Add elements here */ 
                }

            </div>
        )
    }
}

Code code.js, (Automatic class name conversion, if it looks improper)

const ReactCodeProducer = require("react-code-producer")

let App = new ReactCodeProducer()

console.log(App.getComponentCode('box'))

Output node code.js

import React from 'react';
import ReactDOM from 'react-dom';

// React Component class `Box`
class Box extends React.Component {
    render() {
        return (
            <div className="Box">
                { 
                    /* Add elements here */ 
                }

            </div>
        )
    }
}

export default Box;

Code code.js

const ReactCodeProducer = require("react-code-producer")

let AppIndex = new ReactCodeProducer({
    component: {
        code: true,
        names: [
            'App',
            'Index'
        ]
    }
})

console.log(AppIndex.code)

Output node code.js

import React from 'react';
import ReactDOM from 'react-dom';

// React Component class `App`
class App extends React.Component {
    render() {
        return (
            <div className="App">
                { 
                    /* Add elements here */ 
                }

            </div>
        )
    }
}

// React Component class `Index`
class Index extends React.Component {
    render() {
        return (
            <div className="Index">
                { 
                    /* Add elements here */ 
                }

            </div>
        )
    }
}

export default App;
export default Index;

Project Structure

react-code-producer
|
├── LICENSE
├── README.md
├── _config.yml
├── docs
│   └── images
│       └── codepen.png
├── node_modules
│   └── string-format
│       ├── LICENSE
│       ├── README.md
│       ├── index.js
│       └── package.json
├── package-lock.json
├── package.json
├── src
│   ├── index.js
│   └── snippets
│       ├── component.js
│       └── imports.js
└── tests
    └── test.js

Thank you very much.