Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,163,294 members, 7,853,372 topics. Date: Friday, 07 June 2024 at 03:25 PM

Why Does React Work On Codepen? - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Why Does React Work On Codepen? (525 Views)

10 Codepen Awesome Card Design Made With HTML, CSS & JAVASCRIPT. / Why Does Everyone Think Javascript Is Hard? / I Need A Backend Developer To Work On A Project Together. (2) (3) (4)

(1) (Reply) (Go Down)

Why Does React Work On Codepen? by chukwuebuka65(m): 4:21pm On Nov 23, 2022
So they told us that the browser does not understand Jsx. That babel compiles the jsx to a javascript object. But when I go to codepen ( with my browser) . I can write react code , with jsx and it works. So who is doing the compilation? Or is my code sent to a backend where it is compiled and then sent back to the browser. But i don’t think that is the case because it’s happening so fast. As I am typing the coding , I am seeing the output immediately. How are they doing it?
Re: Why Does React Work On Codepen? by ifecorepublic: 4:25pm On Nov 23, 2022
React na JavaScript Library chikina...
Re: Why Does React Work On Codepen? by qtguru(m): 4:52pm On Nov 23, 2022
chukwuebuka65:
So they told us that the browser does not understand Jsx. That babel compiles the jsx to a javascript object. But when I go to codepen ( with my browser) . I can write react code , with jsx and it works. So who is doing the compilation? Or is my code sent to a backend where it is compiled and then sent back to the browser. But i don’t think that is the case because it’s happening so fast. As I am typing the coding , I am seeing the output immediately. How are they doing it?

Both JS and Node, you can use JS to parse XML and convert the markup into DOM API e.g document.createElement, React is parsing JSX and transforming them into JS, it can be done on the browser and backend.

Look at the npm module Acorn, it's what Svelte uses it takes a JSX-like code *.svelte and compiles it into JS and it's written in JS.

AST and Token Parsing

1 Like

Re: Why Does React Work On Codepen? by QuoteJustOnce: 5:53pm On Nov 23, 2022
it works the same as every other online compiler or anything at all where you can input code and get an output.
if you look at the network tab during typing, you would notice that a request is being sent to a server where the magic happens and the result is sent back to the client (you)
a simple hello world html is affixed below

https://i.imgur.com/3Xj2daX.png

1 Like

Re: Why Does React Work On Codepen? by etoluw: 7:29pm On Nov 23, 2022
chukwuebuka65:
So they told us that the browser does not understand Jsx. That babel compiles the jsx to a javascript object. But when I go to codepen ( with my browser) . I can write react code , with jsx and it works. So who is doing the compilation? Or is my code sent to a backend where it is compiled and then sent back to the browser. But i don’t think that is the case because it’s happening so fast. As I am typing the coding , I am seeing the output immediately. How are they doing it?

you can include the babel standalone script to transcribe your code in the browser
Re: Why Does React Work On Codepen? by chukwuebuka65(m): 7:36pm On Nov 23, 2022
QuoteJustOnce:
it works the same as every other online compiler or anything at all where you can input code and get an output.
if you look at the network tab during typing, you would notice that a request is being sent to a server where the magic happens and the result is sent back to the client (you)
a simple hello world html is affixed below

https://i.imgur.com/3Xj2daX.png

Are you saying that for each keystroke , a request is sent to the backend for compilation? I have also seen some pens with React and ReactDom imported at the top of the editor. Why is that?
Re: Why Does React Work On Codepen? by chukwuebuka65(m): 7:48pm On Nov 23, 2022
etoluw:


you can include the babel standalone script to transcribe your code in the browser

I never hear this one before ooo. Even in the react docs where they talked about using react via cdn, they didn’t use JSX but React.createElement(). How do i verify this?
Re: Why Does React Work On Codepen? by chukwuebuka65(m): 7:57pm On Nov 23, 2022
qtguru:


Both JS and Node, you can use JS to parse XML and convert the markup into DOM API e.g document.createElement, React is parsing JSX and transforming them into JS, it can be done on the browser and backend.

Look at the npm module Acorn, it's what Svelte uses it takes a JSX-like code *.svelte and compiles it into JS and it's written in JS.

AST and Token Parsing

If JSX can compiled in the browser using javascript/React, why do we need to do it during our build process then. And why can’t we use JSX while using react via cdn
Re: Why Does React Work On Codepen? by qtguru(m): 11:25pm On Nov 23, 2022
chukwuebuka65:


If JSX can compiled in the browser using javascript/React, why do we need to do it during our build process then. And why can’t we use JSX while using react via cdn

performance

transpiling JSX in runtime is slower than having a generated pure function giving the DOM.

it's like JIT vs AOT
Re: Why Does React Work On Codepen? by chukwuebuka65(m): 7:59am On Nov 24, 2022
qtguru:


performance

transpiling JSX in runtime is slower than having a generated pure function giving the DOM.

it's like JIT vs AOT

Ok makes sense.
Re: Why Does React Work On Codepen? by Deicide: 12:37pm On Nov 24, 2022
You can also you code action on git hub to create react app and code there. grin
Re: Why Does React Work On Codepen? by chukwuebuka65(m): 2:19pm On Nov 24, 2022
Deicide:
You can also you code action on git hub to create react app and code there. grin

Wetin you smoke?

(1) (Reply)

If Any Want Developers For There Hacking Website / Do / Win A 20,000 Naira Jumia Voucher For Just 5 Minutes Of Your Time!

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 19
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.