@lukasbach/scripts

react/fcsimple

Creates a React Functional Component without any props.

Usage

npx @lukasbach/scripts react/fcsimple

You can call the script directly if you have installed it globally:

npm i -g @lukasbach/scripts
ldo react/fcsimple

There is a default shortcut for this script: ldo fcs

You can customize shortcuts with ldo edit-shortcuts.

Arguments

  • [0]: React component name

Options

  • -v, --verbose: Verbose logging

You can also omit options, and will be asked for them interactively.

Add --yes to skip all confirmations.

Script source

View Source on GitHub

/** Creates a React Functional Component without any props. */

const componentName = await ask.text("_", "React component name", "MyComponent");
const content = utils.noindent(`
  import { FC } from "react";
  
  export const ${utils.changeCase.pascalCase(componentName)}: FC = () => (
      <>
        hello
      </>
    );
  `);

await fs.writeFile(path.join(process.cwd(), `${utils.changeCase.kebabCase(componentName)}.tsx`), content);