Lesson 9/100

Tutorials React.js Tutorial

JSX If Statements — Complete Guide

JSX If Statements — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of React.js Tutorial on Toolliyo Academy.

On this page

React.js Tutorial · Lesson 9 of 100

ESLint & Prettier

BeginnerIntermediateAdvancedProfessional

Beginner · 1 — Foundations · ~12 min read · Module 1: Introduction & Setup

Introduction

This lesson is part of the beginner section. We explain ESLint & Prettier slowly, with examples you can copy and run. If something is unclear, read it twice — that is how everyone learns. ESLint finds code problems (unused variables, missing hook rules). Prettier formats code (indentation, quotes) so it looks consistent. Consistent style makes code reviews easier. ESLint catches React-specific mistakes like missing dependency arrays in useEffect.

ESLint & Prettier is setup knowledge. Without it, nothing else in React will run. Spend time here until commands work without copy-paste errors.

When will you use this?

You need this before writing any React code — same as installing Word before writing a document.

  • Every React job expects you to run projects locally with Node and a build tool like Vite.
  • Interviewers often ask you to clone a repo and run npm install && npm run dev on day one.

Real-world: catch hook bugs before merge

A Freshdesk engineer forgets userId in a useEffect dependency array — infinite refetch loop in staging. ESLint react-hooks plugin flags it in the PR before customers see a frozen inbox.

Production-style code

// .eslintrc.cjs
module.exports = {
  extends: ['eslint:recommended', 'plugin:react/recommended', 'plugin:react-hooks/recommended'],
  rules: {
    'react-hooks/rules-of-hooks': 'error',
    'react-hooks/exhaustive-deps': 'warn'
  }
};

// Flagged code in PR:
useEffect(() => {
  loadTickets(filter); // uses filter but deps missing
}, []); // ⚠ react-hooks/exhaustive-deps

What happens in production: Common React foot-guns are caught locally and in CI — same guardrails used at Meta, Airbnb, and Indian product companies.

Lesson example (start here)

Copy this smaller example first. Once it works, compare it with the real-world code above.

npm install -D eslint prettier eslint-config-prettier
// .eslintrc or eslint.config.js enables rules for React

Line-by-line walkthrough

CodeWhat it means
npm install -D eslint prettier eslint-config-prettierPart of the ESLint & Prettier example — read it together with the lines before and after.
// .eslintrc or eslint.config.js enables rules for ReactComment — notes for humans; the computer ignores it.

How it works (big picture)

  • ESLint warns in the editor.
  • Prettier runs on save to auto-format.
  • Together they reduce silly bugs and formatting debates.

Do this on your computer

  1. Add ESLint to a Vite project: npm create vite often includes a lint option.
  2. Install Prettier and enable format on save in VS Code.
  3. Fix red squiggles before committing code.
  4. Read the real-world section and name which part of the app uses this topic.
  5. Run the example locally and confirm the same behavior in the browser.
  6. Change one value in the example (text, initial state, or URL) and predict what will happen before you save.

Experiments — try changing this

  • Change text or labels in the example and save — watch the browser update.
  • Break the code on purpose (remove a bracket), read the error message, then fix it.

Remember

ESLint = catch bugs and bad patterns. Prettier = auto-format code. Fix lint errors early.

Common questions

Is linting required?

Not required to run React, but strongly recommended on real projects.

How long should I spend on ESLint & Prettier?

Until you can explain it in your own words and run the example without looking at the answer. Beginners often need 30–60 minutes per new hook or routing topic; setup lessons may take one afternoon.

What if I get stuck on ESLint & Prettier?

Re-read the line-by-line walkthrough, check the browser console for red errors, and compare your code character-by-character with the example. Search the exact error text — someone else had it too.

Where is ESLint & Prettier used in real jobs?

See the real-world section above — the same pattern appears in LMS, banking, e-commerce, and SaaS products. Interviewers ask you to explain it using one concrete example from your project or this lesson.

Interview prep for this lesson

Practice these questions aloud after reading—each links to a full structured answer.

Mid PDF Detailed
React Developer Tools:?
Short answer: Use the Profiler tab to measure the render times and identify slow components. Check for unnecessary re-renders and optimize with React.memo or shouldComponentUpdate. Real-world example (ShopNest) ShopNest’…
Mid PDF Detailed
Mock axios:?
Short answer: import axios from 'axios'; jest.mock('axios'); axios.get.mockResolvedValue({ data: 'mock data' }); Example code import axios from 'axios'; jest.mock('axios'); axios.get.mockResolvedValue({ data: 'mock data'…
Mid PDF Detailed
Choose a Testing Library: Use libraries like Jest (test runner) and React Testing?
Short answer: Library (for testing React components). Real-world example (ShopNest) ShopNest’s storefront is React: components for ProductCard, CartDrawer, and CheckoutForm, with hooks for local UI state. Say this in the…
Mid PDF Detailed
Only call hooks at the top level?
Short answer: (Don’t call hooks inside loops, conditions, or nested functions.) Real-world example (ShopNest) ShopNest’s cart icon uses useState for count and useEffect to load the cart once on mount. Say this in the int…
Mid PDF Detailed
Mock axios: import axios from 'axios'; jest.mock('axios');?
Short answer: xios.get.mockResolvedValue({ data: 'mock data' }); xios.get.mockResolvedValue({ data: 'mock data' }); xios.get.mockResolvedValue({ data: 'mock data' }); xios.get.mockResolvedValue({ data: 'mock data' }); Re…
Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

React.js Tutorial
Course syllabus

React.js Tutorial

Module 1: React Basics & Setup
Module 2: Props, Events & Lists
Module 3: Forms & Hooks
Module 4: Routing & Data
Module 5: State & Authentication
Module 6: Architecture & React 19
Module 7: Performance
Module 8: Full-Stack & Real-Time
Module 9: Testing & Deployment
Module 10: ShopCart Projects
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details