React is a JavaScript library used to build interactive and reusable user interfaces. It helps developers create modern web applications by dividing the interface into small, reusable components.
React is an open-source JavaScript library for building user interfaces.
React
↓
User Interface
↓
Web Application
It is commonly used to create dynamic and interactive interfaces.
React uses JavaScript as its programming language. JavaScript knowledge helps you understand React concepts more easily.
JavaScript
↓
React
↓
Interactive UI
React is generally described as a JavaScript library rather than a complete programming language.
A library provides reusable functionality that developers can use in their applications.
JavaScript
+
React Library
↓
Web Application
React helps developers create the visual interface of an application.
A user interface is the part of an application that users see and interact with.
User
↓
Buttons
Forms
Menus
Cards
Tables
↓
React UI
React applications are commonly divided into components. Each component can represent a specific part of the interface.
Application
|
+-- Header
+-- Navbar
+-- Sidebar
+-- Content
+-- Footer
A major advantage of components is that the same component can often be reused in different parts of an application.
Button Component
↓
Login Page
↓
Product Page
↓
Contact Page
function Welcome() {
return <h1>Hello React</h1>;
}
The Welcome function represents a simple React
component that returns an interface element.
A React component can be used inside another component.
function App() {
return (
<div>
<Welcome />
</div>
);
}
React uses JSX, which allows developers to write HTML-like markup inside JavaScript.
function App() {
return <h1>Welcome</h1>;
}
JSX is not exactly HTML. It is a syntax that is transformed into JavaScript for use by React.
React does not replace CSS. CSS can still be used to style React applications.
React
+
CSS
↓
Styled User Interface
You can use regular CSS as well as other styling approaches in React projects.
React allows components to respond to user events.
function App() {
function showMessage() {
alert("Hello!");
}
return (
<button onClick={showMessage}>
Click Me
</button>
);
}
State represents information that can change while a component is being used.
Initial State
↓
User Action
↓
State Changes
↓
UI Updates
React provides Hooks such as useState for managing state
in functional components.
Props allow a component to receive data from another component.
<Student name="Rahul" />
The Student component can use the supplied
name value.
React can display data that changes during the application's execution.
Data
↓
React Component
↓
User Interface
When relevant state changes, React can update the interface to reflect the new data.
React can render multiple elements from JavaScript arrays.
const courses = [
"HTML",
"CSS",
"JavaScript",
"React"
];
The map() method is commonly used to convert array data
into React elements.
React can display different content depending on a condition.
{isLoggedIn
? <Dashboard />
: <Login />
}
This allows an interface to respond to application state.
Hooks are functions provided by React that allow functional components to use different React features.
useState()
useEffect()
useRef()
useContext()
The useState Hook allows a functional component to keep
track of state.
const [count, setCount] = useState(0);
Here, count stores the current value and
setCount updates it.
The useEffect Hook is commonly used to perform side
effects in functional components.
useEffect(() => {
console.log("Component loaded");
}, []);
React applications can communicate with backend APIs to retrieve or send data.
React
↓
HTTP Request
↓
Backend API
↓
Database
↓
Response
↓
React
APIs often return data in JSON format. React can use that data to display information to users.
{
"id": 1,
"name": "Amit",
"course": "React"
}
React Router can be used to create navigation between different views or routes in a React application.
/home
/about
/contact
/courses
It helps organize navigation in applications with multiple views.
React is commonly used to create single-page applications, where the browser can update the displayed interface without requiring a traditional full-page navigation for every interaction.
Browser
↓
React Application
↓
Components
↓
Dynamic UI
User
↓
Event
↓
Component
↓
State / Props
↓
React
↓
Updated UI
This basic flow helps explain how React applications respond to user interaction and data changes.
A modern React project commonly contains source files and project configuration files.
my-react-app/
│
├── src/
├── public/
├── package.json
└── node_modules/
The exact structure can vary depending on the project setup and tools being used.
React projects commonly use npm or another JavaScript package manager to install packages and run development commands.
npm install
npm run dev
The available commands depend on the project configuration.
React can be used to build many types of web interfaces and applications.
Before learning React, it is helpful to understand the following JavaScript concepts:
In simple words, React provides a component-based way to build interactive user interfaces with JavaScript.
JavaScript
↓
React
↓
Components
↓
Props + State
↓
Interactive UI
↓
Web Application
Once you understand components, JSX, props, state, events, and Hooks, you can start building useful React applications.
Question: What is React mainly used for?