20
loading...
This website collects cookies to deliver better user experience
function App(){
console.log('Hello World'); // logs 'Hello World'
}
App();
App
function which outputs 'Hello World' in the console. function App() {
return (
<h1>
Hello World
</h1>
);
}
<h1>
with a text 'Hello World' in the Webpage. A component defined in React is just a Javascript function
// JS
function App(){
return 'Hello World';
}
// React
function App() {
return (
<h1>
Hello World
</h1>
);
}
App()
would actually be rendered by ReactDOM
from react-dom package.import ReactDOM from "react-dom";
import App from "./App";
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
<App />
the returned HTML is rendered by ReactDOM into the rootElement.Read More about ReactDOM.render() on the react docs
<div>
with the id root.<div id="root"></div>
<div id="root">
<h1 class="App">Hello World</h1>
</div>
App
function is called JSX.function App() {
return (
<h1>
Hello World
</h1>
);
}
App
would be sent to JS engine like below code that is just pure javascript.function App() {
return (
React.createElement("h1", null, "Hello World")
);
}
import React from 'react';
function App() {
return (
<h1>Hello World</h1>
);
}
// This JSX syntax:
return <h1>Hello World</h1>
// is converted to this call:
return React.createElement("h1", null, "Hello World")
// and that becomes this element object:
{type: 'h1', props: null, children: ["Hello World"]}
"Babel compiles JSX down to React.createElement() calls." - React Docs
// No import 'React' from 'react' needed
function App() {
return (
<h1>Hello World</h1>
);
}
import { jsx as _jsx } from "react/jsx-runtime";
function App() {
return (
_jsx("h1", {
children: "Hello World"
});
);
}
A JavaScript library for building user interfaces
ReactDOM.render(<App />, rootElement);
<App />
into the <div>
that we specified.<h1>
tag in the Virtual DOM, this virtual DOM would be synced with real DOM and during this process <h1>
tag is added to real DOM. This process is called ReconciliationThe costliest operation on Web is DOM painting and manipulation.
Declarative : You just tell what you need and don't need on DOM and React would take care of that for you!
For the end-users, it is all just HTML, CSS, and JavaScript!