React JS
React JS
Open your terminal or command prompt and run the following command to
install create-react-app globally:
cd hello-world-react
Creating Your First React JS Component
1. Identifying Components And Props
2. Creating The HelloWorld Component
3. Integrating The HelloWorld Component
(1) Locate src/App.js
function App() {
return (
<div className="App">
{/* Your code will go here */}
</div>
);
}
function HelloWorld() {
return (
<div>
Hello World in React JS
</div>
);
}
function App() {
return (
<div className="App">
<HelloWorld />
</div>
);
}
function HelloWorld() {
return (
<div>
<h1>Hello World in React JS</h1>
</div>
);
}
function HelloWorld() {
return (
<div className="helloWorld">
<h1>Hello World in React JS</h1>
</div>
);
}
Elements are the smallest building blocks of React apps. An element describes what you want to see on the screen.
Conditional Rendering In JSX
const isLoggedIn = true;
const element = (
<h1>
{isLoggedIn ? 'Welcome back!' : 'Please log in.'}
</h1>
);
Rendering an Element into the DOM
Let’s say there is a <div> somewhere in your HTML file:
<div id="root"></div>
function Hello(props) {
return <h1>Hello World!</h1>;
}
function tick() {
const element = (
<div>
<h1>Hello, world!</h1>
<h2>It is {new Date().toLocaleTimeString()}.</h2>
</div>
);
root.render(element);
}
setInterval(tick, 1000);
ParentC
class ParentComponent extends Component {
render() {
return (
<h1>
I'm the parent component.
<ChildC />
</h1>
);
} const ChildC = () => {
} return <p>I'm the 1st!</p>;
};