gg
Understanding React Auth & Hooks 🛠React: useState vs useRef vs useMemo + Login Explained 1️⃣ useState vs useRef useState is for updating and re-rendering the component. useRef stores a value across renders without causing a re-render. const [count, setCount] = useState(0); const countRef = useRef(0); 2️⃣ useRef vs useMemo useRef stores values or DOM nodes. useMemo is for performance, caching results of calculations. const value = useMemo(() => expensiveCalc(num), [num]); 3️⃣ How Login Works in React User fills login form React sends data to backend Backend validates and sends token React stores token Future requests include token 4️⃣ Where Token is Stored Tokens are stored in: localStorage sessionStorage Cookies (more secure) 5️⃣ Who Generates the Token? The backend (e.g. Express, Django) generates the token and returns it to React. React stores and uses it for authentication.