Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React: npm command to create a new component?

I'm new to React and I want to create a new component by a command.

The command which I want to create will be the same output of the command in Angular 2: "ng generate component Test".

I have search on the internet and there is a reference: https://www.npmjs.com/package/create-reactjs-component.

However, it doesn't work for me. The terminal shows errors:

PS C:\Users\anhtranv1\Desktop\react-app> npm install -g create-reactjs-component Test
npm ERR! code E404
npm ERR! 404 Not Found: Test@latest
npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\anhtranv1\AppData\Roaming\npm-cache\_logs\2018-10- 
29T10_39_16_863Z-debug.log

Is there anyone can give me a command to create a component in react?

Thank you in advanced.

like image 269
anhtv13 Avatar asked Oct 29 '18 10:10

anhtv13


People also ask

How do you create a component in React command?

First, create a new project. Open a terminal, then run the following command: npx create-react-app tutorial-03-component.

Can we create React app using npm?

Create React App CLI tool removes all that complexities and makes React app simple. For this, you need to install the package using NPM, and then run a few simple commands to get a new React project. The create-react-app is an excellent tool for beginners, which allows you to create and run React project very quickly.

What is npm build in React?

npm run build creates a build directory with a production build of your app. Set up your favorite HTTP server so that a visitor to your site is served index.html , and requests to static paths like /static/js/main.<hash>.js are served with the contents of the /static/js/main.<hash>.js file.


1 Answers

With npm install -g create-reactjs-component you install the npm package globally.

After you installed the package globally with the above command you can create a component with create-reactjs-component YourComponentName.

Please read the documentation of the package, it's all described there.

like image 164
Christopher Dosin Avatar answered Sep 22 '22 10:09

Christopher Dosin