React Setup and Project Structure

Setting up a React project takes minutes with modern tooling.

Create a Project (Vite)

Bash
npm create vite@latest my-app -- --template react
cd my-app
npm install
npm run dev          # starts at http://localhost:5173

Project Structure

Code
my-app/
├── src/
│   ├── App.jsx          # Root component
│   ├── main.jsx         # Entry point
│   ├── index.css        # Global styles
│   └── components/      # Your components go here
├── public/               # Static assets
├── index.html
├── package.json
└── vite.config.js

package.json

JSON
{
  "name": "my-app",
  "private": true,
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview"
  },
  "dependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  },
  "devDependencies": {
    "@vitejs/plugin-react": "^4.0.0",
    "vite": "^5.0.0"
  }
}

Adding Packages

Bash
npm install axios             # HTTP client
npm install react-router-dom  # Client-side routing
npm install lodash-es         # Utility functions

Running and Building

Bash
npm run dev        # development server with hot reload
npm run build      # production build to dist/
npm run preview    # preview production build locally

Tips

  • Use Vite for new projects — it's faster than Create React App.
  • Put reusable components in src/components/.
  • Keep components small — one component, one job.

Next: components.