Skip to main content

REACT JSX AND RENDER FUNCTION

REACT JSX AND RENDER FUNCTION

Hi. Today, we are going to discuss about React JSX and the React JS render() function. If you are reading about react for the first time, I recommend you check out our article on getting started with React JS. Subscribe on our YouTube channel to get the video content of our articles here.

JSX

Having a good understanding of JSX is very important as it applies directly in React JS and equally React Native which we will cover subsequently. 

JSX stands for JavaScript and XML which is a standard to write HTML in React JS or JavaScript code. It might look strange but you will get it later on! 

Even though there is an alternative for JSX, many developers consider it easier when working with React JS and React Native. Coding React JS apps without JSX is really challenging.

Talking about JSX, lets look at an example:

const greetings = <h1> hello, world </h1>;

The code above can be overwhelming right ?... Yes! and it is called JSX. HTML in JavaScript.

Also, JavaScript expressions can be passed along with the HTML code or tags in curly braces {}. For example;

const name = trycoder;

const greetings = <h1> hello, {name} </h1>;

<h1> hello I am {5} today

The above codes still work perfectly. If your html elements contain children, you can represent them this way;

const greetings = (

<div>

<h1> I love JSX </h1>

<h2> JSX is cool </h2>

);

Are you getting the point?...!

When working with JSX, make sure you have a top element or parent element, else React will throw an error.

Render () Function

Now let’s talk about the render () function. The render function actually enables React JS to display the webpage that ought to be displayed. It is very simple to understand as it takes just two arguments;

  • The HTML code and the
  • Root Node

The HTML code is actually what will be rendered on the webpage which in most cases is represented as JSX while the root node is the HTML element (like a container) where the HTML code will be rendered.

Let’s look at an example.

From the React JS installation boiler-plate, open the src folder and adjust the codes in the file index.js to what you see below.

index.js

import React from 'react';
import ReactDOM from 'react-dom';
const name = "trycoder.com";
const greetings =

hello, welcome to {name}

ReactDOM.render(greetings, document.getElementById('root'));

OUTPUT

REACT JSX AND RENDER FUNCTION

Thanks for coding with me.

Bye!

Comments

Popular posts from this blog

Introduction to flask

Hello. Welcome to another session on this platform. If you are new here, please do checkout our previous articles on python programming language and stay excited on this session because we are entering into one of python’s web-based application called flask. In this article, we are going to see the following What is flask Prequistes Installation of flask in python Some of flask template engine. What is flask? Flask is one of python-based framework which is used to create web applications. Flight is a very light web framework. During installation, flask comes with pre-installed modules and functions which are used to backup your own web applications. Flask is very easy to understand and perfect go-to for beginners and with flask, a web server can run in less than 3 lines of code. Prequistes Before learning flask, we recommend the reader to have a basic mastery of python concepts. Installation of flask  Before installing flask, we have to checked if python has been installed or. If n...

How to generate random numbers using NumP1

Hello. Welcome to another edition on this platform. For more better understanding, do checkout our YouTube channel to get the video tutorial. In this article of today, we are going to see how to generate random numbers using any of the following methods: Generating a random number Generating a random float and integer Generating random number arrays Generating random number from an array What is a random number? This is a number which cannot be predicted before its occurrence. This number might not different every time. Programmatically, they are two categories of random numbers:     Pseudo-Random numbers       True Random numbers. Just as programs which are written by programmers are a set of instructions, we must follow an algorithm to generate random numbers. Random numbers which are generated using an algorithm are called Pseudo-Random numbers. To generate a true random number, it is important to get the data from sources such as the keyboards, mou...

Introduction to Django

Hello. Welcome to another session on this platform. If you are new here, please do checkout our previous articles on python programming language and stay excited on this session. we are entering into one of python’s application called Django. In this article, we are going to discuss the following: What is Django Why must we use Django  A brief history of Django Installation of Django Popularity of Django What is Django? Python has so many framework application and Django happen to be one of them. Being a python-based-framework, it is used to quickly create web applications.  When building websites, django provides similar ready-made components to handle user authentication, forms, a way to upload components. Why use django? Django is very fast. It takes applications from concept to applications very quickly Django has thousand available packages in it when it is installed. With django, we can launch web applications is a matter of hours. Django is a highly is secured and helps...