react-code-producer

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

View on GitHub

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 &

Box At Codepen

Note

{ 
    /* Add elements here */ 
    
}

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

Getting started

Examples (Code samples)

Example 1 - Single Component

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>
        )
    }
}

Example 2 - Single Component, 2nd usage style

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;

Example 3 - Multiple Components

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.