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
02

React · Lesson 2 of 15 · 3 min

JSX, Functional Components & Props

This is where you prove you understand React's declarative nature and one-way data flow.

JSX is syntactic sugar, not a template language

JSX looks like HTML, but it's not. It's a syntax extension that transpiles directly to React.createElement() function calls. <div>Hello</div> becomes React.createElement('div', null, 'Hello').

This knowledge isn't trivia; it explains React's rules.

  1. Single Root Element: A function can only have one return value. That's why your component's JSX must be wrapped in a single element or a Fragment (<>...</>).
  2. JS Keywords: Attributes like class and for become className and htmlFor because they are reserved keywords in JavaScript, and JSX attributes become keys in a JavaScript object.
  3. Expressions: You can embed any JavaScript expression inside {} because you're already inside JavaScript.

In an interview, when asked "What is JSX?", don't just say "it's like HTML in JavaScript." A better answer: "JSX is syntactic sugar for the React.createElement function. It lets us write declarative UI that looks like HTML, but with the full power of JavaScript. It transpiles to plain JavaScript objects that React uses to build the DOM."

Components are just functions

In modern React, your components are JavaScript functions that take one argument—props—and return JSX. That's it.

// A component is a function that returns UI.
// It receives data via a 'props' object.
const UserProfileCard = ({ name, bio, children }) => {
  return (
    <div className="card">
      <h2>{name}</h2>
      <p>{bio}</p>
      {/* 'children' is a special prop for nested content */}
      <div className="card-actions">
        {children}
      </div>
    </div>
  );
};

// A parent component uses it and passes props.
const App = () => {
  return (
    <main>
      <UserProfileCard
        name="Alex"
        bio="Frontend developer specializing in React."
      >
        <button>Contact</button>
        <button>View Portfolio</button>
      </UserProfileCard>
    </main>
  );
};

This simplicity is the point. They are easy to read, easy to test (input props, assert output JSX), and don't carry the baggage of this context like old class components.

Props enforce one-way data flow

Props are the mechanism for passing data from parent to child. This flow is strictly unidirectional. A child component receives props but can never modify them.

This one-way data flow is a core principle of React. It makes your application predictable. When you see a bug, you can trace the data down the component tree from its source. If a child could modify its props, data could change anywhere, making debugging a nightmare.

The trap: Trying to change a prop inside a child component, like props.name = 'new name'. This will throw an error in strict mode and reveals a fundamental misunderstanding of React's architecture. If a child needs to communicate a change upwards, the parent passes down a callback function as a prop.

The special children prop

The children prop isn't magic. It's just a property that holds whatever JSX you nest inside a component's opening and closing tags.

Look at the UserProfileCard example again. The two <button> elements inside <UserProfileCard>...</UserProfileCard> are passed as props.children. This is React's primary composition model. It lets you create generic "wrapper" components like cards, modals, or layouts that don't need to know what they will contain.

Try it

Create a Badge component. It should accept a color prop (a string like 'red' or '#00ff00') and a children prop. Use the color prop to set the backgroundColor via an inline style object. The component should render the children inside a <span>.

Next: Now that you can pass data down, we'll learn how components manage their own data with useState and respond to side effects with useEffect in "State Management with useState & useEffect".

Lock it in — apply this lesson under interview conditions.

Try an AI mock interview
Previous

Introduction to React & Basic Setup

Next

State Management with useState & useEffect