What React Does (and Doesn't Do) (2024)

React doesn’t do a whole lot.

Don’t get me wrong – it’s great at what it does! But the things React is actually responsible for, in a fully-functioning production app? That list is pretty small. The universe of things you might call “a React problem” or “a React thing” is probably smaller than you think.

What React Does (and Doesn't Do) (1)

What React Does

React is a UI library. It draws components on a web page. You write components as JavaScript functions or classes, pass them to React, and it will call them to figure out what the page should look like.

What React Does (and Doesn't Do) (2)

After it’s done rendering the page, it stops. It is not constantly running in the background waiting for something to happen. You described what to render, React rendered it, and React is done.

The illusion of interactivity, then, is a series of starts and stops.

React Re-renders When You Trigger It

You click a button, that changes something, and React kicks off another render cycle.

An HTTP call comes back with new data to display: that kicks off another render cycle.

Maybe your code set up a listener for a websocket when it started up, and that listener is fired when a message comes in. That could kick off another render cycle.

Every one of these re-renders is in response to a state change. React only re-renders when you tell it to, by changing the state within a component.

What React Does (and Doesn't Do) (3)

So: if a button is clicked, but that click doesn’t trigger a state change? React will not know that anything happened. (again: it’s not constantly running in the background)

If a tree falls in the forest and that tree didn’t call setState… well, as far as React is concerned that tree is still standing.

What React Doesn’t Do

It might be easier to get a gut feel for what React does by seeing some of the things it doesn’t do.

Fetching Data

React doesn’t know how to make API calls. For that you need the fetch function built into browsers, or another library. Fetching data is not a React problem.

But you’ve gotta do it though, right? Because what good is an app without data? The key is that the actual fetching of the data is just some JavaScript code that runs, and you need to tell React when to run that code – either by queueing it up with the useEffect hook or using the componentDidMount lifecycle.

Centering a div

React cares exactly zero about styling. Think of it as generating the barebones HTML. React will put elements on the page, but everything after that is the job of CSS: how they appear, what they look like, how they’re positioned, and how centered or uncentered they are.

“How to center a div in React” is… not a React problem. It’s a CSS problem. You don’t need “react” in your Google query. Once you figure it out, use React to apply the right CSS class name to your components and voila :)

What React Does (and Doesn't Do) (4)

What about CSS-in-JS libraries like styled-components though? And UI frameworks like Material UI or Reakit? These libraries come with ready-made React components that include some of the CSS baked in, but make no mistake, it’s still CSS doing the styling under the hood.

Special Syntax (other than JSX)

Pop quiz! Which of these bits of syntax are React-specific (not JavaScript)?

a) function Button({ onClick }) { ... }b) const Button = ({ onClick }) => ( ... )c) const [flag, setFlag] = useState(false)

Go ahead, think it over.

If you answered “none of them” you got it right :)

Object Destructuring

a) function Button({ onClick }) { ... }

This first example is using object destructuring to unpack fields from the object that’s being passed to the function.

This is a common pattern for React components, because React passes an object containing the component’s props and their values – but this syntax is standard JavaScript (since ES6, anyway).

When a component is invoked with props, like this:

<Button onClick={someFunction} className="btn" />

React will end up calling the Button function with a plain JS object that looks like this:

{ onClick: someFunction, className: "btn"}

You can write components without that syntax, too. Destructuring the props object is just a nice shorthand. This does the same thing:

function Button(props) { const onClick = props.onClick; ...}

Arrow Functions

b) const Button = ({ onClick }) => ( ... )

This second example is a combination of object destructuring with an arrow function. Arrow function syntax was added to JavaScript with ES6, and it’s a shorthand version of the longer function way of writing it.

No special React syntax here.

Array Destructuring

c) const [flag, setFlag] = useState(false)

This last one has no special React syntax either. The [flag, setFlag] on the left side of the = is using destructuring assignment to pick apart an array into two named variables.

The useState function is part of React, but there’s no special syntax here. It’s just the name of a regular function, which is part of React’s hooks API for state.

Maybe you feel this was a trick question. “It calls useState! That’s a React thing for sure!”

You’re right that useState is a function that React provides! But all of the syntax here: const, the square brackets for array destructuring, calling a function with the value false – that’s all JavaScript. useState is the name of a function. Just as function myThing() { } would create a function called myThing, React includes something like that to create the useState function.

Even the variable names aren’t special. You could write it like const [a, b] = useState(false) and React would never know nor care. It would work fine. (Your coworkers and/or your future self would probably have something to say about those names, though! Conventions are useful for a reason :)

Interpreting Your Components

React is responsible for calling your components, but it doesn’t parse and execute them line by line as an interpreter would. Components are JavaScript functions, so executing them is still the browser’s job.

Rendering a List of Items

Here’s one more for you: which parts of this are React syntax? (some of it actually is, this time!)

function ItemList({ items }) { return ( <ul> {items.map(item => ( <li key={item.id}> {item.name} </li> )} </ul> )}

This code shows the React way to render a list, and the JSX syntax (all the HTML-looking stuff with the <angle brackets>) actually is syntax that isn’t part of JavaScript. JSX is a React thing. (some other frameworks support it too)

JSX lets you embed the result of JavaScript expressions, though, so everything inside {curly braces} is real actual JavaScript syntax.

In my head I think of this as flipping back and forth between contexts. I see <ul> and I think “I’m in JSX now” – which means I can write more tags like <li> or whatever, but I can’t write regular JavaScript.

But then I see a single open brace, and that signifies “I’m back to JavaScript”. Inside those braces I can write JavaScript expressions. That word expression is important though, because I can’t write statements like if or const thing = 7 or a while loop. Only expressions, a.k.a. things that evaluate to a value.

items.map is the first thing inside the brace: that is regular JavaScript code, invoking the map function on the array of items.

Into the map call we’re passing an arrow function, item => .... This function describes how to transform the list of items into a list of something else. It takes one item item at a time, and returns a new thing, “mapping” the item onto another value.

What React Does (and Doesn't Do) (5)

The result of the items.map call is the array of <li>s, and React knows how to render an array of items (as long as they have a key, anyway).

After the closing curly brace } we’re back to JSX-land until the closing </ul> tag.

What else doesn’t React do?

There’s a ton more stuff to do in a web app: Saving stuff to the database. Querying the database. Serving web pages. Sending push notifications. Whatever your app does, there’s a very high chance that React doesn’t do most of it :) (React does none of those things)

Next time you open up Google, and you’re about to type “how to do XYZ in React”, pause for a second and ask yourself whether XYZ is a thing that React does, or if it’s just a thing that your app does. What technology is responsible for that piece of the puzzle? Draw out a block diagram to map out the chain of events. You’ll get better results that way.

And if you’re not sure? Do some searching. When you start to get the feeling that none of the results are answering your question, almost like nobody has ever had this problem before – take heart, because that’s probably not true! But you might be asking the wrong question.

What React Does (and Doesn't Do) (2024)

FAQs

What React Does (and Doesn't Do)? ›

React is responsible for calling your components, but it doesn't parse and execute them line by line as an interpreter would. Components are JavaScript functions, so executing them is still the browser's job.

What does React do that JavaScript doesn't? ›

React and JavaScript FAQs

React has reusable UI components and focuses more on user interface elements than JavaScript. Also, React is primarily used for front-end development while JavaScript works well for both or back-end development. However, JavaScript doesn't have reusable UI components or code for your web app.

When to use React or not? ›

React, when applied correctly, can save tremendous time, effort, and cost in frontend development. If you're working on a frontend UI that demands high user interaction, you'll want to use React. It's a pain to code every one of those interactive elements and binds time together to the underlying business logic.

What does ReactJS do? ›

What is React JS used for? ReactJS's primary goal is to create User Interfaces (UI) which enhance the speed of programs. It makes use of virtual DOM (JavaScript object), which enhances the app's efficiency. Quicker than the standard DOM is the JavaScript virtual DOM.

When not use React? ›

  1. Because you don't like the approach React takes on some topics.
  2. Because React has limitations that you find difficult to work with.
  3. Because for your particular task another framework already has a better tool.
  4. Because you want to try something new.
  5. Because team that you have joined is already using a different tool.
Jan 18, 2024

What is the disadvantage of ReactJS? ›

Drawbacks of ReactJS:

Learning curve. Being not full-featured framework it is requered in-depth knowledge for integration user interface free library into MVC framework. View-orientedness is one of the cons of ReactJS. It should be found 'Model' and 'Controller' to resolve 'View' problem.

Why should I use React instead of JavaScript? ›

Why choose React over plain JavaScript for web development in 2024? React offers advantages like improved code organization, enhanced performance with the Virtual DOM, easier state management, and a thriving community, making it a powerful choice for modern web development projects.

What is React not good for? ›

When you are making an app like a game or a demanding creative app, React is not the best choice. This problem stems from the fact that it uses a Virtual DOM. Virtual DOMs, or VDOMs, are layers that help make unoptimized DOM manipulations faster.

Is it better to React or not? ›

But when emotions are running high, these reactions may not be as helpful or kind as we'd like them to be in the long run. While reacting may feel good in the moment, taking time to let emotions settle and respond from a more grounded place will lead to better outcomes in all of our relationships.

What problem does React solve? ›

React promotes the creation of reusable components, saving time and programmers' effort by eliminating the need to write repetitive code for the same features. Changes made to a particular component do not affect other parts of the application, ensuring a modular and maintainable codebase.

What is ReactJS best for? ›

React provides state-of-the-art functionality and is an excellent choice for developers looking for an easy-to-use and highly productive JavaScript framework. Using React, you can build complex UI interactions that communicate with the server in record time with JavaScript-driven pages.

Why would anyone use React? ›

It allows you to determine how you want to handle routing, testing and even folder structure. Beyond the environment, the fact that React isn't too opinionated means it can be used on a host of different projects: web applications, static sites, mobile apps and even VR.

What is the main advantage of using React? ›

We can develop new features in React without re-writing the existing code. It can also render on the server using Node and power mobile apps using React Native. So we can create IOS, Android, and Web applications simultaneously. In conclusion, extensive code reusability is supported by React.

When should I use React? ›

React is a good fit for projects with multiple state changes that are intertwined and dependent on each other. Changes are tracked on the virtual DOM and then applied to the real DOM, ensuring that React uses the virtual DOM to keep track of changes in the application, then updates the real DOM with those changes.

Why do developers love React? ›

React is Easy to Scale

React doesn't create any unnecessary barriers for developers to build complex applications. Second, React makes no secret about how they 'don't make assumptions about the rest of your technology stack'.

What are some scenarios reasons you wouldn't choose React? ›

js is not enough for developing a website or application without add-ons and other libraries. Of course, this software is easy to combine with other libraries and even programming languages. However, it also means that the developer experience has to be enough to deal with these add-ons.

Does React work without JavaScript? ›

The short answer is yes, it's technically possible to learn React Native without prior knowledge of JavaScript.

Can we do React without JavaScript? ›

Yes , you can start learning React without knowing a bit of JavaScript also , but it will not useful . You will not able to graps the core concept. So, do go for anything in hurry. Take your time and learn JavaScript first , build some project and then go for React.

What problems does ReactJS solve? ›

Traditionally, web development involved manipulating the DOM directly with JavaScript. This approach can be cumbersome, error-prone, and difficult to scale. React solves these problems by providing a more efficient and organized way to build UIs.

What is the difference between React and ReactJS? ›

1) React is a JavaScript library used for building user interfaces, while ReactJS is a JavaScript library specifically for creating UI components. ReactJS is often used interchangeably with React. 2) React allows developers to create reusable components, which helps in building modular and maintainable applications.

Top Articles
[Aktienanalyse] 20 Kennzahlen, ein Unternehmen schnell zu überprüfen - DividendInvestingTom
What Is an Index Fund and Should You Invest Now
What Is Single Sign-on (SSO)? Meaning and How It Works? | Fortinet
Jail Inquiry | Polk County Sheriff's Office
Tattoo Shops Lansing Il
Bild Poster Ikea
Was ist ein Crawler? | Finde es jetzt raus! | OMT-Lexikon
Ret Paladin Phase 2 Bis Wotlk
Chris wragge hi-res stock photography and images - Alamy
Sissy Hypno Gif
Yi Asian Chinese Union
Beds From Rent-A-Center
Tabler Oklahoma
Guardians Of The Galaxy Vol 3 Full Movie 123Movies
Wordscape 5832
Conan Exiles Thrall Master Build: Best Attributes, Armor, Skills, More
Panorama Charter Portal
Jellyfin Ps5
Saatva Memory Foam Hybrid mattress review 2024
623-250-6295
Mychart Anmed Health Login
Heart and Vascular Clinic in Monticello - North Memorial Health
Big Lots Weekly Advertisem*nt
Today Was A Good Day With Lyrics
Low Tide In Twilight Ch 52
Lines Ac And Rs Can Best Be Described As
Cb2 South Coast Plaza
13301 South Orange Blossom Trail
Tu Housing Portal
Gncc Live Timing And Scoring
Ryujinx Firmware 15
Guide to Cost-Benefit Analysis of Investment Projects Economic appraisal tool for Cohesion Policy 2014-2020
91 Octane Gas Prices Near Me
Duke Energy Anderson Operations Center
Bad Business Private Server Commands
Grove City Craigslist Pets
Craigslist Central Il
Magicseaweed Capitola
Pepsi Collaboration
Crazy Balls 3D Racing . Online Games . BrightestGames.com
Cal Poly 2027 College Confidential
Wunderground Orlando
Trivago Anaheim California
Guided Practice Activities 5B-1 Answers
M&T Bank
Child care centers take steps to avoid COVID-19 shutdowns; some require masks for kids
The Average Amount of Calories in a Poke Bowl | Grubby's Poke
New Starfield Deep-Dive Reveals How Shattered Space DLC Will Finally Fix The Game's Biggest Combat Flaw
300+ Unique Hair Salon Names 2024
Is My Sister Toxic Quiz
Peugeot-dealer Hedin Automotive: alles onder één dak | Hedin
How Did Natalie Earnheart Lose Weight
Latest Posts
Article information

Author: Aracelis Kilback

Last Updated:

Views: 6109

Rating: 4.3 / 5 (44 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Aracelis Kilback

Birthday: 1994-11-22

Address: Apt. 895 30151 Green Plain, Lake Mariela, RI 98141

Phone: +5992291857476

Job: Legal Officer

Hobby: LARPing, role-playing games, Slacklining, Reading, Inline skating, Brazilian jiu-jitsu, Dance

Introduction: My name is Aracelis Kilback, I am a nice, gentle, agreeable, joyous, attractive, combative, gifted person who loves writing and wants to share my knowledge and understanding with you.