Introduction to React
React is a JavaScript library for building user interfaces. Created by Facebook, it has become the most popular choice for building modern web applications.
What is React?
React is a declarative, component-based library that makes it easy to build interactive UIs. Instead of manipulating the DOM directly, you describe what your UI should look like, and React handles the updates efficiently.
Why React?
- Component-Based: Build encapsulated components that manage their own state
- Declarative: Design simple views for each state in your application
- Learn Once, Write Anywhere: Use React for web, mobile (React Native), and more
- Large Ecosystem: Massive community, extensive libraries, and great tooling
Your First React Code
Here's a simple React component:
function Welcome({ name }) {
return (
<div className="greeting">
<h1>Hello, {name}!</h1>
<p>Welcome to React.</p>
</div>
);
}
// Usage
<Welcome name="Developer" />
This component takes a name prop and renders a personalized greeting.
Notice how we use curly braces {name} to embed JavaScript expressions
within JSX.
Key Takeaways
- React is a library for building user interfaces
- Components are the building blocks of React applications
- JSX lets you write HTML-like code in JavaScript
- React uses a Virtual DOM for efficient updates