Overview of React Frontend for Full Stack Developers: setting up a React app using Vite or Create React App; JSX, functional components, hooks (useState, useEffect); integrating Firebase in a React app for data access and authentication

React वह दूसरी major front-end library है जिसे जानना worth है: आप JSX में लिखे functional components से UIs build करते हैं, useState और useEffect जैसे hooks से हर component की state और side effects manage करते हैं, और यह same Firebase backend से connect होता है।

12 min read · 9 cards · 2 checks

Read in: English · हिन्दी · ગુજરાતી


Theory

वह दूसरा Big Front End

आपने FestConnect का front end Angular में build किया, पर industry में दूसरा dominant choice React है। एक full-stack developer को दोनों recognise करने चाहिए। यह closing lesson React का एक taste है: इसे पढ़ने के लिए enough, देखने के लिए यह Angular से कैसे compare करता है, और जानने के लिए यह same Firebase backend से connect होता है।

React JSX में लिखे components से UIs build करता है, और useState और useEffect जैसे hooks से state और side effects manage करता है। अगर आप Angular की component thinking समझते हैं, React spirit में familiar लगेगा, हालाँकि style में lighter और ज़्यादा flexible है।

Theory

Components, JSX, और Setup

React components से user interfaces build करने के लिए एक JavaScript library है। आप Vite (fast और modern) या older Create React App से एक project start करते हैं।

Modern React components functions हैं जो JSX return करते हैं, एक syntax जो आपको JavaScript के अंदर directly HTML-like markup लिखने देता है। तो एक component बस एक function है जिसका return value बताता है क्या render करना है। यह Angular के class-and-decorator style से lighter है: एक React component एक single small function हो सकता है। JSX एक जगह markup और logic mix करता है, यही React का signature look है, और एक बार यह click हो जाए, यह बहुत naturally पढ़ता है।

Practical

useState के साथ एक React Functional Component

import { useState } from 'react';

function Counter() {
  const [count, setCount] = useState(0);   // state: [value, setter]

  return (                                 // JSX: HTML-like markup in JS
    <button onClick={() => setCount(count + 1)}>
      Clicked {count} times
    </button>
  );
}
export default Counter;

This example runs in Gri-Learn on the web, where you can edit it and see the output.

Theory

Hooks: useState और useEffect

Hooks functional components में capabilities add करते हैं।

useState एक component को state देता है: const [count, setCount] = useState(0) current value और एक setter return करता है; setter call करना value update करता है और component को re-render करता है। useEffect render के बाद side effects run करता है, जैसे data fetch करना या subscribe करना, एक dependency array से controlled जो बताता है इसे कब re-run करना है (उदाहरण के लिए, एक empty array [] के साथ mount पर एक बार)।

तो useState है 'एक value याद रखिए और यह change होने पर re-render कीजिए', और useEffect है 'render होने के बाद कुछ कीजिए, जैसे data load करना'। साथ में ये ज़्यादातर वह cover करते हैं जो एक component को चाहिए, और यही तरीका है React Firebase से data और auth के लिए connect होता है।

Practical

एक बार Data Load करने के लिए useEffect (जैसे Firebase से)

import { useState, useEffect } from 'react';

function Events() {
  const [events, setEvents] = useState([]);

  useEffect(() => {
    // side effect: fetch once after first render (empty dependency array)
    fetchEventsFromFirebase().then(setEvents);
  }, []);   // [] = run once on mount

  return <ul>{events.map(e => <li key={e.id}>{e.name}</li>)}</ul>;
}
// React integrates with Firebase via the same client SDK used in Angular.

This example runs in Gri-Learn on the web, where you can edit it and see the output.

Quiz

एक React functional component में, useState hook क्या करता है?

  1. यह app के routes define करता है
  2. यह component को state का एक piece देता है: यह current value और एक setter return करता है, और setter call करना value update करता है और re-render कराता है
  3. यह directly database से connect होता है
  4. यह JSX को replace करता है
Show the answer

यह component को state का एक piece देता है: यह current value और एक setter return करता है, और setter call करना value update करता है और re-render कराता है

useState एक functional component में state add करता है: const [value, setValue] = useState(initial) current value और एक setter function return करता है; setter call करना value update करता है और एक re-render trigger करता है तो UI change reflect करे। Option A routing describe करता है (एक router library से handle होता है, useState से नहीं)। Option C एक data-fetching effect या SDK का काम है (अक्सर useEffect के अंदर), useState खुद का नहीं। Option D wrong है: JSX render करने के लिए markup syntax है, जबकि useState data manage करता है; ये साथ काम करते हैं, एक दूसरे को replace नहीं करता। useState एक value याद रखने और update करने का React का तरीका है जो UI drive करती है।

Think first

Angular या React: ये कैसे Compare होते हैं, और आप कौन सा सीखते हैं यह Matter करता है?

अब आप Angular और थोड़ा React दोनों जानते हैं। ये कैसे अलग हैं, और एक full-stack developer को choice की worry करनी चाहिए? फिर tap कीजिए।

Show the answer

ये same problem solve करते हैं, component-based UIs build करना, पर अलग philosophies के साथ, और CONCEPTS जानना specific choice से कहीं ज़्यादा matter करता है। ANGULAR एक full, opinionated FRAMEWORK है: इसमें बहुत कुछ built in है (routing, forms, dependency injection, HttpClient), default से TypeScript इस्तेमाल करता है, और चीज़ें करने का एक structured तरीका prescribe करता है। यह large teams और apps के लिए powerful है क्योंकि ज़्यादातर tasks के लिए एक standard तरीका है, हालाँकि इसका मतलब है upfront ज़्यादा सीखना। REACT view पर focused एक lighter LIBRARY है: यह आपको components, JSX, और hooks देता है, और कई choices (routing, data fetching, state management) आपको या add-on libraries को छोड़ देता है। यह इसे flexible और quickly start करने लायक बनाता है, पर आप stack का ज़्यादा हिस्सा खुद assemble करते हैं। कोई भी universally 'better' नहीं है, ये structure को flexibility के लिए trade करते हैं, और दोनों huge production apps power करते हैं। जो truly transfer होता है वह shared MENTAL MODEL है जो आप build कर रहे हैं: reusable components के trees की तरह UIs, inputs/props के through नीचे flow करता data, events के through ऊपर flow करती events, render क्या होता है इसे drive करती state, और नीचे same backend (Firebase, एक API)। एक बार आप components और state में सोचना शुरू करते हैं, Angular और React के बीच move करना ज़्यादातर same ideas के लिए different syntax सीखना है। तो एक full-stack developer को दोनों पढ़ने में comfortable होना चाहिए, framework-versus-library trade-off समझना चाहिए, और project और team के आधार पर pick करना चाहिए, कौन सा 'right' है इस पर agonise नहीं करना चाहिए। Concepts deeply सीखिए; specific tool एक detail है जिसे आप switch कर सकते हैं।

Theory

BCA603-01 Complete

आपने end to end एक full-stack application concept build किया है: एक Angular front end (components, routing, forms, reusable UI, deployment), एक Express/Node REST backend (routes, middleware, Mongoose के through MongoDB), दोनों JSON APIs से connected और Firebase Auth और JWTs से secured, plus Firestore और React का एक taste। यही full-stack web development का complete arc है। अब आप modern web app की किसी भी layer के बारे में reason कर सकते हैं, और इन्हें एक real, deployable product में connect कर सकते हैं। Web पर build करने के लिए एक strong foundation।

Summary

Key takeaways

  • React components से UIs build करने के लिए एक popular JavaScript library है; Vite या Create React App से set up कीजिए।
  • Modern React components functions हैं जो JSX return करते हैं, JavaScript के अंदर लिखा एक HTML-like syntax।
  • useState एक component को state देता है: यह value और एक setter return करता है, और update करना component को re-render कराता है।
  • useEffect render के बाद side effects (data fetch करने जैसे) run करता है, एक dependency array से controlled (empty [] mount पर एक बार run होता है)।
  • React Angular में इस्तेमाल हुए same Firebase backend (client SDK) से connect होता है।
  • Angular एक full opinionated framework है; React एक lighter flexible library है, पर दोनों component/state mental model share करते हैं।
  • Memory hook: React = JSX में functional components, state के लिए useState, side effects के लिए useEffect; concepts Angular से transfer होते हैं।

Study this properly

This page is the lesson to read. In Gri-Learn the same topic is a graded deck: the self-checks are scored and your weak topics are tracked. Free to start.

Start this topic

Already have an account? Sign in

More from Firebase and React Integration

Gri-Learn · syllabus-mapped B.C.A. lessons in English, Hindi and Gujarati