
Introduction
React JS is one of the most popular JavaScript libraries used for building user interfaces, especially for web applications. It helps developers create fast, scalable, and interactive applications.
In this guide by TechYantram, you will learn the basics of React JS including components, JSX, props, state, and hooks.
What is React JS?
React JS is a JavaScript library developed by Facebook for building user interfaces. It allows developers to create reusable UI components.
Why Use React JS?
React is widely used because it offers several benefits:
- Reusable components
- Fast performance with virtual DOM
- Easy to learn and use
- Strong community support
Setting Up React
You can create a React app using the following command:
npx create-react-app my-app cd my-app npm start
Understanding JSX
JSX stands for JavaScript XML. It allows you to write HTML-like code inside JavaScript.
const element = <h1>Hello TechYantram</h1>;
Components in React
Components are the building blocks of a React application.
Function Component Example
function Welcome() {
return <h1>Hello User</h1>;
}
Props in React
Props are used to pass data from one component to another.
function Welcome(props) {
return <h1>Hello {props.name}</h1>;
}
State in React
State is used to manage dynamic data in a component.
import { useState } from "react";
function Counter() {
const [count, setCount] = useState(0);
return (
<button onClick={() => setCount(count + 1)}>
Count: {count}
</button>
);
}
React Hooks
Hooks allow you to use state and other features in functional components.
Common hooks:
- useState
- useEffect
- useContext
Real-World Use Cases
React is used in:
- Web applications
- Dashboards
- E-commerce websites
- Social media platforms
Best Practices
- Use functional components
- Keep components small and reusable
- Use proper folder structure
- Avoid unnecessary re-renders
Conclusion
React JS is a powerful library for building modern web applications. By understanding its core concepts like components, JSX, props, and state, you can start building your own projects.
TechYantram recommends practicing with small projects to gain confidence in React.
FAQs
What is React JS?
React is a JavaScript library for building user interfaces.
Is React easy to learn?
Yes, beginners can learn React with basic JavaScript knowledge.
What are React hooks?
Hooks allow you to use state and lifecycle features in functional components.