Q1 - React Basics & Fundamentals
25 Marks1. What is React?
React is a JavaScript library created by Facebook for building user interfaces. It helps you build fast, interactive websites by automatically updating only the parts that changed.
Instagram uses React. When you like a post, only the like count updates, not the entire page. This makes it super fast!
React ایک JavaScript library ہے جو Facebook نے بنائی ہے۔ یہ ہمیں تیز اور interactive websites بنانے میں مدد کرتی ہے۔ جب کوئی چیز بدلتی ہے تو صرف وہی حصہ update ہوتا ہے، پورا صفحہ نہیں۔
2. JSX - Write HTML in JavaScript
JSX looks like HTML but it's actually JavaScript. React converts it to JavaScript automatically.
JSX ایک ایسی چیز ہے جو HTML جیسی لگتی ہے لیکن یہ JavaScript ہے۔ React اسے خود بخود JavaScript میں بدل دیتا ہے۔
3. Components - Building Blocks
Components are like LEGO blocks. You create small pieces and combine them to build bigger things.
Components ایسے ہیں جیسے LEGO کے ٹکڑے۔ ہم چھوٹے ٹکڑے بناتے ہیں اور انہیں ملا کر بڑی چیزیں بناتے ہیں۔
Create a component called "Greeting" that displays "Welcome to React!"
Q2 - React Theory & Concepts
20 Marks (CPS)1. Props - Passing Data
Props are like function parameters. You pass data from parent to child component.
Props ایسے ہیں جیسے function کے parameters۔ ہم parent سے child کو ڈیٹا بھیجتے ہیں۔
2. Props Destructuring
Instead of using props.name, we can directly extract the values.
Create a User component that receives firstName, lastName, and email as props and displays them.
Q3 - React Hooks & Fetching APIs
20 Marks (4 Parts)Part 1: useState Hook - Managing State
useState lets you add state to functional components. It returns [value, function to update value].
useState ایک Hook ہے جو state بناتا ہے۔ یہ دو چیزیں دیتا ہے - value اور اسے update کرنے کا function۔
Part 2: useEffect Hook - Side Effects
useEffect runs code after component renders. Perfect for fetching data.
Part 3: Fetching Data from APIs
Use fetch() inside useEffect to get data from servers.
Create a component that fetches a list of posts from an API and displays them.
Q4 - Advanced React Concepts
20 Marks (6 Parts)Part 1: React Forms - Controlled Components
Forms in React are controlled by state. Every input change updates state.
Part 2: Event Handling
React uses camelCase for events: onClick, onChange, onSubmit, etc.
Part 3: useContext - Global State
useContext lets you share data without passing props through every component.
Create a form with multiple input fields and display the form data in another component using useState.
Q5 - ES6 & Advanced Topics
15 Marks (6 Parts)Part 1: ES6 Array Methods
map(), filter(), and reduce() are essential for React development.
map() ہر چیز کو بدل دیتا ہے، filter() صرف مناسب چیزیں رکھتا ہے، اور reduce() سب کو ایک میں ملا دیتا ہے۔
Part 2: Conditional Rendering
Show or hide content based on conditions.
Part 3: Lists and Keys
When rendering lists, always use a unique key prop.
جب ہم list بناتے ہیں تو ہر item کو ایک unique key دینا ضروری ہے۔ یہ React کو بتاتا ہے کون سی چیز کون سی ہے۔
Create a list of products with map() and filter them based on price using filter().
💡 Practical Exam Questions
These are the type of questions your teacher might ask. Practice these thoroughly!
Question 1: Product Fetching Component (Most Important!)
Question: Create a React component that simulates fetching a list of products {id, title, price} using setTimeout inside useEffect. Manage product data, loading state, and error state using multiple useState hooks. Implement a search filter that updates the displayed list in real-time based on user input. Render the filtered products list using .map with a stable unique key and display appropriate conditional messages (Loading..., No products found, Error).
یہ component products fetch کرتا ہے، loading اور error states manage کرتا ہے، search filter کرتا ہے، اور .map سے products دکھاتا ہے۔ یہ سب کچھ ایک ساتھ کرنا ضروری ہے۔
Try to write this component from scratch without looking at the code. This is exactly what your teacher might ask!
50 Multiple Choice Questions
Test your knowledge! Select the correct answer for each question.
⭐ Important Topics
1. Hooks - MOST IMPORTANT!
Hooks are the most important feature in modern React. You MUST master these:
- useState: Manage component state
- useEffect: Handle side effects and data fetching
- useContext: Share data globally
- useNavigate: Navigate between pages
Hooks React کا سب سے اہم حصہ ہیں۔ یہ functional components میں state اور دوسری features استعمال کرنے دیتے ہیں۔ ہر exam میں hooks کے سوالات آتے ہیں۔
2. ES6 Features - VERY IMPORTANT!
ES6 features are used everywhere in React:
- Arrow Functions: () => {}
- Destructuring: const { name } = obj
- Spread Operator: ...array
- Template Literals: `Hello ${name}`
- Array Methods: map(), filter(), reduce()
3. React Fundamentals
Never forget these basics:
- Components: Building blocks of React
- Props: Data from parent to child
- State: Data that can change
- JSX: HTML-like syntax in JavaScript
- Virtual DOM: React's optimization technique
4. Common Exam Questions
Q: What is the difference between props and state?
Props are read-only data from parent. State is data that can change inside component.
Q: Why do we use keys in lists?
Keys help React identify which items have changed, been added, or been removed.
Q: When should we use useEffect?
Use useEffect for fetching data, subscribing to events, or any side effects.
Q: What is the Virtual DOM?
A copy of the DOM in memory. React updates this first, then updates only changed parts on real DOM.
- Practice writing components from scratch
- Understand the flow of data (props)
- Master useState and useEffect
- Practice the practical exam questions
- Take the 50 MCQs multiple times
- Read the Urdu summaries for better understanding
- Don't memorize, understand the concepts