Welcome to this introductory tutorial on React! React is a popular JavaScript library for building user interfaces. It's declarative, component-based, and highly efficient, making it a fantastic choice for modern web development.
At its core, React allows you to build complex UIs from small, isolated pieces of code called components. These components can be reused and managed independently, leading to more organized and maintainable code. React also uses a virtual DOM, which makes updates to the UI incredibly fast.
The easiest way to start a new React project is by using Create React App. It sets up a modern build pipeline for you with no configuration required.
npx create-react-app my-react-app
cd my-react-app
npm start
This command will start a development server and open your new React application in your default web browser. You should see the default React welcome page.
Let's create a simple component. Open the file src/App.js
. You'll see something like this:
import React from 'react';
import './App.css';
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;
Now, let's modify it to display a simple greeting:
import React from 'react';
import './App.css';
function App() {
return (
<div className="App">
<header className="App-header">
<h1>Hello from React!</h1>
</header>
</div>
);
}
export default App;
Save the file, and your browser should automatically update to show "Hello from React!".
The syntax you see in React components, like Congratulations! You've taken your first steps into the world of React. From here, you can explore concepts like: Keep building, experimenting, and exploring the vast possibilities with React!{`
Key JSX Rules:
className
instead of class
for CSS classes.{`{myVariable}`}
.Next Steps