Last Updated : 02 Nov, 2023
React.createElement is a fundamental method of React JS. The main use of React.createElement is the Creation of a React component. It is the JavaScript format for creating react components. Also, the JSX react component when transpired invokes this only method for creating the component.
Syntax:React.createElement(type,{props},children);
// JSX code
<type {props} >{children}</type
Parameters: React.createElement() takes three arguments. They are:
React DOM: React DOM contains the arguments that are necessary to render react elements in the browser.
ReactDOM.render(element,containerElement);
Parameters: ReactDOM.render() takes two arguments:
Step 1: Create a react application using the below command:
npx create-react-app foldername
Step 2: Once your folder is created, change your directory to the newly created folder using the below-mentioned command.
cd foldernameProject Structure: Project Structure
Example: This code in Index.js shows the use of react.createEement method and render that component using ReactDOM.render method.
JavaScript
// Filename - index.js
import React from 'react';
import ReactDOM from 'react-dom';
let demo = React.createElement(
"h1", { style: { color: "green" } }, "Welcome to GeeksforGeeks"
)
ReactDOM.render(
demo,
document.getElementById('root')
);
Step to run the application: Run your application using the following command in the terminal.
npm start
Output: This output will be visible on http://localhost:3000
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4