Explore
Module 1 · Part 1 of 12 · Free preview

Part 1

Chapter 1: The jQuery Hangover...--The year is 2014. You have just been handed a ticket to add a "real-time search filter" to an e-commerce website. The existing codebase is 5,000 lines of jQuery held together with duct tape and prayers. To implement this one feature, you must manually select DOM elements, write logic to hide and show product cards, manage a timer to debounce keystrokes, and then—because the search results affect the shopping cart counter in the header—find that specific element by its ID and update its text content. If you forget to update the counter, no error appears. The page just silently shows the wrong number. Welcome to the world of imperative UI programming.Before React, this was the daily reality for front-end developers. jQuery was king because it smoothed over browser inconsistencies (remember Internet Explorer 6?).

But as applications grew from simple websites into complex web apps like Gmail, Trello, and Figma, the imperative approach hit a wall. Every new feature required you to trace a spiderweb of DOM manipulations scattered across dozens of event handlers. There was no single source of truth. The UI displayed whatever state the DOM happened to be in at that moment after a series of mutations. If a user clicked "Add to Cart," you prayed that your $(".cart-count").text(newCount) line executed in the correct order and that no other function overwrote it.This chapter is not just about learning syntax. It is about a fundamental mental shift: from telling the browser how to update the UI to telling React what the UI should look like, and letting React figure out the rest.The Declarative AwakeningReact introduced a radical idea: declarative programming.

Instead of writing a step-by-step recipe for DOM manipulation, you write a description of the UI for any given state. When the state changes, React re-renders the entire description, calculates the minimal set of DOM operations needed, and applies them for you. You stop thinking about how to insert a element and start thinking about what the list should contain.Let us see the difference. In jQuery, adding a to-do item might look like Listing 1-1.javascriptCopyDownload// Listing 1-1: Imperative jQuery approach

Keep reading — free

Sign in with your SamEnrico account to read the whole of lesson 1.

Sign in