DEV Community

Optional chaining with React

Aki Rautio on December 09, 2019

13.1.2020 UPDATE: Babel 7.8.0 supports optional chaining out of the box Optional Chaining is one of the most requested features in Javascript (and...
Collapse
 
slashgear_ profile image
Antoine Caron

Hey !

I don't really agree with the conclusion of your article.
Using this feature now is quite dangerous for you web performances. The way babel is transpiling the optional chaining is quite disgusting (ok, like every polyfill), but this one is not really necessary.

If you try to use it everywhere is your apps, you should notice that your bundle will swell quickly.

I wrote an article explaining why we should avoid this feature for now.

Collapse
 
akirautio profile image
Aki Rautio

I would agree that performance wise it's not the best and the transpiled code looks ugly. But if this starts to cause performance issues, I would rather optimize the Babel transpiling than trying to fix it inside the application. Transpiling won't be eventually needed for most of browsers so this is a "temporary" issue.

Collapse
 
p4lm profile image
Henrik Sommerfeld

I really like this. For my Gatsby project with VS Code, all I had to do was to click the TypeScript version number (which was 3.6.3) in the Status bar and choose Use Workspace Version 3.7.3. Done!

Collapse
 
akirautio profile image
Aki Rautio

Oh so cool :) That's even easier way to get VSCode to work with this!