Hey Programmers, Welcome to the Fourth Part of React JS Tutorial Series In the Previous Parts We Learned About ES6 In React. And In this Post, We Will Be Learning About How to Render HTML In React. So Before Proceeding With Our Tutorial If you Have Missed the Previous Part of Our Series You Can Acess Them Here:
What Is Render Function In React?
React Render Renders HTML Content to a Web Page Or Website Using a Function Called ReactDOM.render(). We Use Render to Show the HTML Code’s Content In a React JS Website.
You Might Have Noticed That When We Created Our First React App There Was a Folder Called index.html, In that Particular File We will be Rendering Our HTML Content to React.
We Don’t Directly Render Our HTML Content in that index.html File Instead We Use a <div> Tag, In this Div Container We Put Our HTML In Order to Render Our HTML Content Into React.
Using Render Function In React
ReactDOM.render(<Hello />, document.getElementById('reactDiv'))
<body>
<div id="reactDiv"></div>
</body>
Creating an Element In React JS
HTML CODE:
const new_element = (
<h2> Hello this a React Element </h2>
);
ReactDOM.render(new_element, document.getElementById('reactDiv'))
Root Node
Root Node is Used to Display the HTML element Where We are Going to Display the Result. We Don’t Use <div> For This.
<body>
<header id="reactDiv"></header>
</body>
Displaying the Result
ReactDOM.render(<Hello />, document.getElementById('reactDiv'))
So This Was It For this Post See you In the Next One Till Then Keep Coding Keep Exploring!
- The JS Developer’s Podcast [EP: 1] Introduction to JavaScript - September 27, 2024
- Which is the Best Operating System for Programming? Here are 3 OS to Consider - August 24, 2024
- Top 10 Cybersecurity Threats to Watch Out for in 2024 - August 17, 2024
Pingback: JSX In ReactJS | ReactJS Tutorial #5 - Mr Programmer
Pingback: What are Components In ReactJS | ReactJS Tutorial #6 - Mr Programmer
Pingback: Props In ReactJS | ReactJS Tutorial #7 - Mr Programmer