After understanding the folder structure, let’s explore the npm scripts defined in your package.json file. These scripts typically look like this:
"dev": "vite",
"build": "vite build",
"lint": "eslint .",
"preview": "vite preview"You can run them using npm run <script> in your terminal:
npm run dev: Runs the app locally in development modenpm run lint: Checks for code style and syntax issuesnpm run build: Builds the app for productionnpm run preview: Previews the production build (requires npm run build first)The first React component is defined in src/App.jsx. It’s a JavaScript function written in PascalCase and is known as a function component.
function App() {
return (
Hello React
);
}
export default App;To start fresh, you can clear the contents of App.css and index.css.
Variables declared inside the function are redefined on every render. If a variable doesn’t depend on anything inside the component, it’s better to define it outside:
const title = 'React';
function App() {
return (
Hello {title}
);
}
export default App;This avoids unnecessary redefinition and improves performance.
npm scripts help you run, build, and test your React project efficiently. By starting with a simple function component, you can focus on learning JSX, component structure, and variable scope. As you progress, you’ll explore props, state, and more advanced patterns in React.