CLI for creating new React components

Usage no npm install needed!

<script type="module">
  import chancedigitalNewComponent from 'https://cdn.skypack.dev/@chancedigital/new-component';


new-component logo


Simple, customizable utility for adding new React components to your project.

Anyone else sick of writing the same component boilerplate, over and over?

This project is a globally-installable CLI for adding new React components. It's dead simple to use, and requires no configuration, although it's easy to customize it to fit your project's coding style.


  • Simple CLI interface for adding various flavors of React components:
    • Function components
    • Components with forwarded refs*
    • React.Component class
    • React.PureComponent class
  • Uses Prettier to stylistically match the existing project.
  • Offers global config, which can be overridden on a project-by-project basis.
  • Colorful terminal output!
  • Now supports TypeScript!*

* Supported as-of version 2.0


# Using Yarn:
$ yarn global add @chancedigital/new-component

# or, using NPM
$ npm i -g @chancedigital/new-component

cd into your project's directory, and try creating a new component:

demo of CLI functionality

By default, the new component will be created in the src/components directory relative to the directory from which the command is run, but you have a few options.

If you pass the --index argument, the component will be saved along with its stylesheet and an index file in its own sub-directory. This might be useful if you are building a particularly large component with multiple sub-files and you feel better organizing things this way. Prior to version 2 this was the default behavior, but I generally prefer flat folder structures so this is now opt-in.

Your project will now have a new directory at src/components/Button. This directory has two files:


Configuration can be done three different ways:

  • Creating a global .new-component-config.json in your home directory (~/.new-component-config.json).
  • Creating a local .new-component-config.json in your project's root directory.
  • Command-line arguments.

The resulting values are merged, with command-line values overwriting local values, and local values overwriting global ones.

API Reference


Control the type of component created:

  • functional for a functional component (default),
  • forward-ref for a functional component with a forwarded ref,
  • class for a traditional Component class, or
  • pure-class for a PureComponent class,


Command line: --type <value> or -t <value>

JSON config: { "type": <value> }


Controls the desired directory for the created component. Defaults to src/components


Command line: --dir <value> or -d <value>

JSON config: { "dir": <value> }


Controls the type of style file created for the component:

  • css (default),
  • scss,
  • less,
  • stylus,
  • module.css,
  • module.scss, or
  • NONE for no stylesheet


Command line: --style <value> or -s <value>

JSON config: { "style": <value> }

File Extension

Controls the file extension for the created components. Can be either js (default) or tsx for TypeScript components.


Command line: --extension <value> or -x <value>

JSON config: { "extension": <value> }


Controls whether or not the component is created in its own sub-directory with an index file. Defaults to false.


Command line: --index or -i

JSON config: { "index": true|false }

Prettier Config

Delegate settings to Prettier, so that your new component is formatted as you'd like. Defaults to Prettier defaults.

For a full list of options, see the Prettier docs.


Command line: N/A (Prettier config is only controllable through JSON)

JSON config: { "prettierConfig": { "key": "value" } }


  "prettierConfig": {
    "singleQuote": true,
    "semi": false,

Platform Support

This has only been tested in macOS. I think it'd work fine in linux, but I haven't tested it. Windows is a big question mark (would welcome contributions here!).


This is a brand new thing! I'd like to add more functionality:

  • Built-in support for more style tools (Aphrodite, styled-components, etc).
  • Better error messaging, more edge-case support
  • Editor integrations :o


To get started with development:

  • Check out this git repo locally; you will need to ensure you have npm installed globally.
  • In the folder run npm install
  • Check that command runs node ../new-component/src/index.js --help
  • Alternatively you can set up a symlink override by running npm link then new-component --help. Note: this will override any globally installed version of this package.