Welcome to the world of React! If you're new to web development or just starting with React, you're in the right place. In this guide, we’ll take a look at what React is, why it’s important, and the interesting story behind its creation. Let's begin!
React is a JavaScript library for building user interfaces. It was created by Facebook (now Meta) to help developers build fast and interactive web applications. With React, you can create web pages that update automatically when data changes, without needing to reload the page manually.
Before React, developers had to write a lot of code to manage updates on a webpage. Every time something changed (like a new message or a new comment), the entire page had to reload or update manually. This was slow and inefficient.
React makes web development faster, simpler, and more efficient by:
React was created at Facebook to fix a frustrating issue," where notifications showed unread messages that didn’t exist. The problem arose because messages were displayed in multiple places but didn’t stay in sync. To solve this, Facebook engineers built React, which updates the UI efficiently using the Virtual DOM. This improved performance and fixed inconsistencies, leading to React’s public release in 2013. Today, it’s one of the most popular web development tools.
Today, big companies like Instagram, WhatsApp, Airbnb, Uber, Netflix, and many more use React to build web applications. Learning React can open up great career opportunities, whether you're building your own project or looking for a job in tech.
Now you understand what React is and why it was created, it's time to dive in! Step by step, we’ll learn how React works while also building some exciting projects along the way.
React is a JavaScript library developed by Facebook for building user interfaces (UIs), especially for single-page applications (SPAs). It makes it easier to build dynamic web apps by breaking the UI into reusable components.
Vanilla JavaScript refers to using plain, native JavaScript without any libraries or frameworks. It’s powerful but can get verbose and harder to manage as your app grows in complexity.
| Feature | Vanilla JS | React |
|---|---|---|
| DOM Manipulation | Manual and verbose | Abstracted via virtual DOM |
| UI Reusability | Custom functions & HTML templates | Component-based |
| State Management | Manual state tracking | Built-in state with hooks (useState) |
| Performance Optimization | Manual tuning | Virtual DOM diffing |
| Learning Curve | Lower (initially) | Slightly higher, but scales better |
Vanilla JS is like building a car from scratch using metal, bolts, and an engine.
React is like assembling a car using high-quality prebuilt components (engine block, seats, dashboard) with flexible customization.
<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
<title>Vanilla JS Button</title>
</head>
<body>
<div id="app"></div>
<script>
const app = document.getElementById('app');
const button = document.createElement('button');
button.textContent = 'Click Me';
button.style.padding = '10px 20px';
button.style.fontSize = '16px';
button.addEventListener('click', () => {
alert('Hello from Vanilla JS!');
});
app.appendChild(button);
</script>
</body>
</html><!-- react.html -->
<!DOCTYPE html>
<html>
<head>
<title>React Button</title>
<script src="https://unpkg.com/react@18/umd/react.development.js" crossorigi></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
function App() {
const handleClick = () => {
alert('Hello from React!');
};
return (
<button
onClick={handleClick}
style={{ padding: '10px 20px', fontSize: '16px' }}
>
Click Me
</button>
);
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);
</script>
</body>
</html>onClick is syntactic sugar around event listeners.| Feature | Vanilla JS | React |
|---|---|---|
| DOM Access | document.getElementById | Not needed; declarative rendering |
| Event Binding | addEventListener | onClick, onChange via props |
| UI Definition | HTML + JS DOM Manipulation | JSX + Component function |
| Readability | Lower for large apps | High (especially with reuse) |
In Chapter 2, we’ll: