@lukasbach/scripts

react/fcchildren

Creates a React Functional Component with a PropsWithChildren prop type.

Usage

npx @lukasbach/scripts react/fcchildren

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

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

There is a default shortcut for this script: ldo fcc

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 with a PropsWithChildren prop type. */

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

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