Frontend School
DashboardProblemsLearnPracticeMock InterviewReportsStatsBuy Credits
DashboardProblemsLearnPracticeMock Interview
React Interview Essentials
  1. 1.Introduction to React & Basic Setup
  2. 2.JSX, Functional Components & Props
  3. 3.State Management with useState & useEffect
  4. 4.Conditional Rendering & List Management
  5. 5.Event Handling & Form Management
  6. 6.React Router for SPA Navigation
  7. 7.Context API for Global State
  8. 8.Working with Refs & the DOM
  9. 9.Advanced Component Patterns: HOCs & Render Props
  10. 10.Building Reusable Logic with Custom Hooks
  11. 11.Performance Optimization with Memoization
  12. 12.Error Boundaries for Robust UIs
  13. 13.Concurrent React & Suspense
  14. 14.Testing React Components with RTL
  15. 15.Advanced State Management (Overview)
React Interview Essentials
01

React · Lesson 1 of 15 · 4 min

Introduction to React & Basic Setup

Your first interview screen will test if you can explain React's core model and build a project from scratch. This is how you pass it.

How to explain React's core value

When asked "What is React?", don't just say it's a "JavaScript library for building UIs." That's true but says nothing. Your answer must cover two points: its declarative nature and its component-based architecture.

First, React is declarative. You describe the UI you want for a given state, and React handles the "how." This is the opposite of imperative code, where you manually find a DOM node and change its text or class. Declarative code is more predictable and easier to debug because the UI is a direct function of the state.

Second, it's component-based. You break down complex UIs into small, reusable pieces. Each component encapsulates its own logic and markup. This makes code easier to maintain, test, and share across a team.

The follow-up question is always "How does it work?" Your answer is the Virtual DOM. Instead of touching the real browser DOM for every change (which is slow), React builds a lightweight copy in memory—the Virtual DOM. When state changes, it creates a new Virtual DOM tree, compares it with the previous one (a process called "diffing"), and computes the minimal set of changes needed. It then batches these changes and applies them to the real DOM in one efficient update.

Scaffolding a new project with Vite

Create React App (CRA) is dead. The modern standard for starting a new React project is Vite. It's an order of magnitude faster because it uses native ES modules in the browser during development, avoiding the slow, heavy bundling process that CRA required.

To create a new project, run one command. Use the TypeScript template; it's the professional standard.

npm create vite@latest my-react-app -- --template react-ts

This creates a new directory named my-react-app. Navigate into it, install dependencies, and start the development server.

cd my-react-app
npm install
npm run dev

The server will start, usually on http://localhost:5173. Open it in your browser. You now have a running React application with hot module replacement (HMR), meaning your changes will appear instantly without a full page reload.

How the application boots up

Understanding the project's entry point is crucial. When you open your new Vite project, you'll see a few key files that work together to render your app.

my-react-app/ ├── public/ │ └── index.html # The single HTML page shell ├── src/ │ ├── App.tsx # The root React component │ └── main.tsx # The application entry point ├── package.json # Project dependencies and scripts └── ...

The process is simple:

  1. The browser loads public/index.html. This file is mostly empty, containing just a single <div id="root"></div>.
  2. The HTML file loads your compiled JavaScript, starting with src/main.tsx.
  3. The code in main.tsx tells React to find the div with the ID root and render the <App /> component inside it.

This flow, from a static HTML file to a dynamic React application, is how all single-page applications (SPAs) work.

Anatomy of a component

At its core, a React component is just a JavaScript function that returns something that looks like HTML. This "HTML in JS" is called JSX.

Let's strip the default App.tsx down to its essentials.

// src/App.tsx

function App() {
  // The return statement contains JSX
  return (
    <div>
      <h1>My React App</h1>
      <p>This is the root component.</p>
    </div>
  )
}

export default App

This App function is a component.

  • It's a standard JavaScript function. By convention, component names are PascalCase.
  • It returns JSX, which describes the UI for this component.
  • export default App makes this component available to be imported and used by other files, like main.tsx.

The trap: Candidates often forget what JSX actually is. It is not HTML. It's syntactic sugar for JavaScript function calls. The browser doesn't understand JSX. During the build process, a tool like Babel transpiles every JSX tag into a React.createElement() call.

For example, <h1>Hello</h1> becomes React.createElement('h1', null, 'Hello').

Knowing this demonstrates a deeper understanding than just writing tags. It also explains why you must use className instead of class for CSS classes in JSX—class is a reserved keyword in JavaScript.

Try it

Create a new React project with Vite and TypeScript. Once it's running, open src/App.tsx, delete all the boilerplate code inside the return statement, and replace it with a single <h1> containing "Hello, World!" and a <p> tag with a short sentence. Confirm your changes appear in the browser instantly.

Next: You'll learn how to write JSX, create your own functional components, and pass data between them using props in the lesson on JSX, Functional Components & Props.

Lock it in — apply this lesson under interview conditions.

Try an AI mock interview
Next

JSX, Functional Components & Props