Quickest Star Orbiting a Black Hole

In a recently published paper in The Astrophysical Journal, a team of European astrophysicists has published results of studying stars orbiting around the supermassive black hole at the center of our…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Getting Started With JSX and HTML in JavaScript

For one of my personal projects, I found myself writing a lot of verbose vanilla javascript to create DOM elements, append text, add classes, attributes and event listeners — my code got really messy fast like this:

Image1: Creating HTML DOM nodes with classes, attributes, values etc in vanilla javascript.

It turns out incorporating HTML in your javascript code with JSX is quite simple.

For those who don’t know about JSX, it’s code that looks like HTML that you write in your javascript code to create HTML elements.

To use JSX you need to use a transpiler like babel in your project. If you haven’t used babel, I highly recommend you learn about it, as it powers so much of the modern javascript code that developers write today.

The previous image was simple, and some of you might still not see the value of using JSX over creating DOM elements in vanilla javascript. But as your codebase grows, complexity grows and having a tool like JSX to abstract things away can make ourlives as developers easier.

Image3: An example of DOM creation code, which I eventually swapped out for JSX.

You can download very small example app created by opening your terminal and running these commands on your machine:

Add a comment

Related posts:

Understanding Federal and State Standards on Reasonable Suspicion

Reasonable suspicion is one of several reasons an employer may rely on to require employees to submit to a drug or alcohol test. But what does having “reasonable suspicion” really mean when applying…

Fantasy Console yang Membuatmu Bernostalgia

Bagi kamu yang lahir di tahun 80–90 an, apakah masih ingat dengan game-game bertema 8bit yang sering dimainkan di console lawas yang ada di rumah mu dulu atau di abang-abang tukang game di depan…

Minimum Viable Friendship

Thanks to social media, an increasingly faster communicating world, and the rise of personal networking lifehacks, the landscape of friends, acquaintances and other folks in your life that expect…