Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does a null mean in React createElement()?

Tags:

reactjs

return React.createElement("div", null, "Hello ", this.props.name);

What does a null mean in React the above createElement() execution?

like image 852
thinker Avatar asked Aug 14 '16 13:08

thinker


People also ask

What does the React createElement () method return?

createElement() Create and return a new React element of the given type. The type argument can be either a tag name string (such as 'div' or 'span' ), a React component type (a class or a function), or a React fragment type. Code written with JSX will be converted to use React.

Can you use createElement in React?

Using React without JSX is especially convenient when you don't want to set up compilation in your build environment. Each JSX element is just syntactic sugar for calling React. createElement(component, props, ...children) . So, anything you can do with JSX can also be done with just plain JavaScript.

IS NULL A React node?

A React Node is one of the following types: Boolean (which is ignored) null or undefined (which is ignored)

How do you check if a React is null?

To check for null in React, use a comparison to check if the value is equal or is not equal to null , e.g. if (myValue === null) {} or if (myValue !== null) {} . If the condition is met, the if block will run. Copied!


1 Answers

React.createElement(type, props, children);

The props parameter is a JavaScript object passed from a parent element to a child element. When you say null means you are not passing any props to that component.

~~

type in React.createElement can be a string like h1, div etc or a React-Component.

var reactElement = React.createElement('div', { className: 'header' });

In this particular case when you pass prop { className: 'header' } , createddiv element will have cssClass associated with it.

like image 191
Praveen Prasad Avatar answered Sep 28 '22 06:09

Praveen Prasad