Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for React Under The Hood: What’s Really Happening?
Travis Ramos
Travis Ramos

Posted on • Originally published attravislramos.com

     

React Under The Hood: What’s Really Happening?

React has long been a go-to JavaScript library and is easily one of the most popular in the world. Also, with popular frameworks like Next.js and Remix being built on top of React and the ability to do mobile development with React-Native, this library is not going away anytime soon. The problem with this however is that most beginners flock to React and start learning it without really understanding how it works. So let’s dive in.

How JSX Works

In React, JSX (JavaScript XML) is a syntax that looks similar to HTML but works within JavaScript. It’s not valid JavaScript itself, so React uses a transpiler (usually Babel) to convert JSX into standard JavaScript. This JavaScript code is what the browser ultimately interprets.

When you write JSX, it gets transformed intoReact.createElement() function calls. These function calls produce React elements, which are the building blocks of a React application. Each element represents a piece of the UI.

Here’s an example of what that looks like:

JSX in a React Component

const element = (  <div>    <h1>Hello, React!</h1>    <p>This is a paragraph.</p>  </div>);
Enter fullscreen modeExit fullscreen mode

JSX Transformed into #"http://www.w3.org/2000/svg" width="20px" height="20px" viewbox="0 0 24 24">Enter fullscreen modeExit fullscreen mode

React takes these nestedReact.createElement() calls and converts them into the corresponding HTML elements in the browser’s DOM.

Conclusion

JSX makes writing React components easier by allowing you to write syntax similar to HTML, but it’s just syntactic sugar forReact.createElement() calls that create the structure of your app using JavaScript. This is what allows React to manage the UI efficiently through its Virtual DOM mechanism.

If you enjoyed this article, you might also enjoy my free newsletter I send out every week to developers just like you. You can sign uphere.

Top comments(2)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
omorfarukmahfuj profile image
Omor Faruk Mahfuj
Hi, I'm Omor Faruk Mahfuj, a UI designer and web developer passionate about creating visually appealing and functional websites.

what is syntactic sugar?

CollapseExpand
 
travislramos profile image
Travis Ramos
Code + Coffee = ❤️Let's make you the best developer you can be!
  • Location
    Houston
  • Work
    Frontend Developer at WaterlooData & Full Stack Immersive Web Instructor at DigitalCrafts
  • Joined

Syntax that is easier to read and write but that isn't actually compiled that way.

So what I'm saying in the article is React components lets you write JSX code which looks like HTML when you write it, but when it's compiled by the browser it is actually React.createElement() functions.

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Travis Ramos
Code + Coffee = ❤️Let's make you the best developer you can be!
  • Location
    Houston
  • Work
    Frontend Developer at WaterlooData & Full Stack Immersive Web Instructor at DigitalCrafts
  • Joined

More fromTravis Ramos

The Resurgence of Server-Side Rendering in the JavaScript Era
#react#javascript#nextjs#webdev
What's New in Next.js 15: Key Updates for Developers
#nextjs#react#javascript#webdev
State vs Props in React
#react#reactnative#beginners#webdev
DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp