r/javascript • u/lhorie • Sep 22 '20
Introducing the New JSX Transform
https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html42
u/Ambroos Sep 23 '20
This has the interesting side effect that simple functional JSX components (without hooks) would become completely reusable across libraries with zero changes!
1
u/boobsbr Sep 23 '20
How so?
2
Sep 23 '20 edited Sep 23 '20
Because it returns just a object which can be parsed by any javascript library. Before it returned an result of a react call.
Edit: Sorry im wrong there. Misread something.
1
u/lhorie Sep 23 '20
Not quite. It allows you to specify the function that produces said object without needing to explicitly import a library at the top level. The actual shape of the object is an implementation detail, which the corresponding library will be able to consume.
1
u/Meowish Sep 23 '20 edited May 17 '24
Lorem ipsum dolor sit amet consectetur adipiscing, elit mi vulputate laoreet luctus. Phasellus fermentum bibendum nunc donec justo non nascetur consequat, quisque odio sollicitudin cursus commodo morbi ornare id cras, suscipit ligula sociosqu euismod mus posuere libero. Tristique gravida molestie nullam curae fringilla placerat tempus odio maecenas curabitur lacinia blandit, tellus mus ultricies a torquent leo himenaeos nisl massa vitae.
2
2
73
u/ILikeChangingMyMind Sep 22 '20
With the new transform, you can use JSX without importing React.
Dan Abramov promised this a few months ago in a GitHub issue thread, but I wasn't sure I could really believe him until I saw this.
Awesome improvement React team!
8
u/nowtayneicangetinto Sep 23 '20
Dan is a god damned genius. I have crazy respect for that guy.
22
u/valtism Sep 23 '20
Do we know if he wrote this feature? Dan is a great guy and really puts himself out there in the community, but people treat him like he’s the one writing all of react.
-9
u/KeytapTheProgrammer Sep 23 '20
Or declare React to be a global. With Webpack, you can use it's ProvidePlugin to do this, for example. QED no
import React from 'react'required.
36
u/madcaesar Sep 22 '20
Ok I'm completely stupid, what is the point of this? Everywhere I use JSX is a react app that's imported already for other parts and tree shook for performance.
Can someone share a real life use case of this?
16
u/jdeath Sep 22 '20
Depending on your setup, its compiled output may slightly improve the bundle size. It will enable future improvements that reduce the number of concepts you need to learn React.
probably that stuff
30
u/Attack_Bovines Sep 22 '20
I may be interpreting it wrong, but it looks like tech debt cleanup from the paradigm shift to functional components.
1
-27
0
Sep 23 '20
[deleted]
1
Sep 24 '20 edited Sep 24 '20
HTML is and always has been written in Javascript since it is not dynamic, that's what the Dom-Api is for. JSX is not HTML, it calls createElement to piece together dynamic UI. Doing that manually is hard to scale, hence your rant was typed right into a React component.
0
Sep 22 '20
[deleted]
11
10
u/RainyCloudist Sep 23 '20
If you’re not importing react in your projects then it’s likely that it imports it for you at build time.
Common way to do this using webpack is by using webpack’s ‘ProvidePlugin’ method.
You’re probably using some nice tool to start your projects which takes care of all that for you. :)
4
u/ShortFuse Sep 23 '20
It appears Typescript includes JSX support. VSCode is bundled with Typescript, so this might be what's going on.
3
50
Sep 22 '20
[removed] — view removed comment
0
Sep 22 '20
[deleted]
32
Sep 22 '20
[removed] — view removed comment
0
Sep 22 '20
[deleted]
8
Sep 23 '20
IDEs are literally just glorified text editors, so saying an IDE could do this is kind of like saying notepad could do this.
If you don't see the code in the file, it's not there.
Do you mean the build sequence maybe? It's possible for transpilation tools (such as webpack) to insert something like this during the build process.
52
Sep 22 '20
[removed] — view removed comment
0
29
u/ouralarmclock Sep 22 '20
Hmm, I thought JSX was already decoupled and used something like
_h()under the hood. I remember reading about something using JSX with Vue instead of template blocks and assumed it just worked because of that.