InterviewSolution
| 1. |
How to start a project in React? |
|
Answer» There are mainly TWO ways to start a project in React - First is to setup React with Webpack and Babel from Scratch. The second way is to use the user-friendly way provide by Facebook ie using create-react-app. The create-react-app also under the hood uses babel and webpack to compile your React code to PLAIN HTML, CSS, and JavaScript. So, we can set them manually in React. But it is a lengthy and complicated process. On the other hand, create-react-app is a simple way to start with React and provided by Facebook. The way is a bit different for npm version 5.2 and up then for 5.1 and down. We will look into the way to create a react app using rpm version 5.2+. So, first, go to your terminal to check your npm version. As I have npm version 6.5, so will use npx create-react-app my-app to create the react app. It will show US the above message once the SYSTEM is ready. Next we cd into the directory and run our local development environment by running npm start If it compiled successfully, we will get the below in our terminal. As instructed, we need to open any web browser and go to http://localhost:3000/ to see our React app. If you use npm 5.1 or EARLIER, you can't use npx. Instead, install create-react-app globally: npm install -g create-react-app Now you can run: create-react-app my-app |
|