🚀 Day 11 of My React JS Journey – Events & Forms in React ⚛️ Today I explored how React handles user interactions and form data, which are essential for building interactive web applications. 🔹 Events in React Events are actions performed by users that trigger a function or cause a change in the UI. Examples include: • Keyboard events • Mouse events • Form events For example, when a user clicks a button to open a modal, we trigger an onClick event. HTML Example <button onclick="add()">Click me</button> What is this? React (JSX) Example <button onClick={add}>Click me</button> <button onClick={() => add(5,3)}>Click me</button> 💡 In React: • Event names use camelCase. • React uses Synthetic Events, which wrap native browser events to provide consistent behavior across browsers. Example using the event object: function getData(e){ console.log(e.target.textContent) } <button onClick={getData}>Click me</button> 🔹 Common React Events Keyboard Events • onKeyDown • onKeyUp Mouse Events • onClick • onDblClick • onMouseOver • onMouseOut • onScroll Form Events • onChange • onInput • onSubmit • onSelect 🔹 Forms in React Forms are used to collect user input and send it to the backend/server through APIs. React forms can be implemented in two ways: 1️⃣ Controlled Components • Form inputs are managed using React state • Events like onChange, onInput, and onSubmit control the input values • Easier to manage validations and dynamic updates Popular form libraries: • React Hook Form • Formik Validation library: • Zod 2️⃣ Uncontrolled Components • Input values are managed directly by the DOM • React accesses them using the useRef hook 💡 Key Takeaway: Understanding events and forms is crucial to build interactive applications where users can input data and trigger actions efficiently. Learning React step by step and strengthening my frontend development skills every day ⚛️🚀 #ReactJS #FrontendDevelopment #JavaScript #WebDevelopment #ReactForms #LearningJourney #DeveloperGrowth
React JS Events and Forms Explained
More Relevant Posts
-
🔄 Understanding useReducer in React When managing state in React, most developers start with useState. But as applications grow, state logic can become complex. That’s where useReducer becomes very useful. Think of useReducer as a more structured way to manage state, especially when multiple state changes depend on specific actions. 📌 What is useReducer? useReducer is a React Hook that lets you manage state using a reducer function. It works similarly to how reducers work in Redux. It takes two main things: 1️⃣ A reducer function 2️⃣ An initial state const [state, dispatch] = useReducer(reducer, initialState); state → the current state dispatch → a function used to send actions reducer → decides how state should change 📌 Example const initialState = { count: 0 }; function reducer(state, action) { switch (action.type) { case "increment": return { count: state.count + 1 }; case "decrement": return { count: state.count - 1 }; default: throw new Error("Unknown action"); } } function Counter() { const [state, dispatch] = useReducer(reducer, initialState); return ( <> <p>{state.count}</p> <button onClick={() => dispatch({ type: "increment" })}> Increment </button> <button onClick={() => dispatch({ type: "decrement" })}> Decrement </button> </> ); } Here, instead of directly updating state like setCount, we dispatch actions and the reducer decides how the state should change. 📌 When Should You Use useReducer? ✅ When state logic is complex ✅ When multiple state updates depend on each other ✅ When managing objects or multiple state values ✅ When you want predictable state transitions 💡 Key Insight useReducer separates state logic from UI logic, making your components easier to read, test, and maintain. As React applications grow, this pattern helps keep your state management clean and scalable. 💬 Are you using **useState or useReducer more often in your React projects? #React #FrontendDevelopment #JavaScript #WebDevelopment #ReactHooks #LearningInPublic
To view or add a comment, sign in
-
-
Day 21: useMemo vs useCallback (Most Confusing React Topic) Many React developers get confused between useMemo and useCallback. But the difference is actually simple 📌 What is useMemo? useMemo is used to memoize a computed value. 👉 It prevents expensive calculations from running again and again. import { useMemo, useState } from "react"; function App() { const [count, setCount] = useState(0); const expensiveValue = useMemo(() => { console.log("Calculating..."); return count * 10; }, [count]); return ( <div> <h1>{expensiveValue}</h1> <button onClick={() => setCount(count + 1)}>Increase</button> </div> ); } ✅ It stores the result/value. 📌 What is useCallback? useCallback is used to memoize a function. 👉 It prevents a function from being recreated on every render. import { useCallback, useState } from "react"; function App() { const [count, setCount] = useState(0); const handleClick = useCallback(() => { console.log("Clicked"); }, []); return ( <div> <button onClick={handleClick}>Click</button> <h1>{count}</h1> <button onClick={() => setCount(count + 1)}>Increase</button> </div> ); } ✅ It stores the function reference. 🔥 Simple Difference ✅ useMemo → returns a VALUE ✅ useCallback → returns a FUNCTION 📌 When to use them? useMemo ✔ Heavy calculations ✔ Derived data useCallback ✔ Passing functions as props ✔ React.memo optimized components 🎯 Interview Line 👉 useMemo memoizes values, useCallback memoizes functions. #ReactJS #useMemo #useCallback #FrontendDevelopment #JavaScript #WebDevelopment #CodingJourney #LearnInPublic
To view or add a comment, sign in
-
I miss the days when a React component was just a simple function that returned some HTML. Now, every time I create a new file, I have a minor existential crisis: Wait, am I on the server or the client? 🌍💻 The shift to React Server Components (RSCs) is arguably the biggest architectural change to frontend development in years. While architecting the UI for the Railway Management System I'm building, I had to completely rewire how I think about rendering. In a traditional React Single Page Application (SPA), we ship a massive bundle of JavaScript to the user's browser, make their device parse it, and then show a loading spinner while we fetch the train schedules from the Spring Boot API. It works, but it’s heavy. Here is how modern React is completely flipping the script, and how I'm applying it: 🚄 1. Server Components (The New Default): These run entirely on the server and ship zero JavaScript to the browser. I use these for the heavy lifting—like rendering the static search layouts, reading directly from the backend, and handling SEO. The browser just receives raw, lightning-fast HTML. 🖱️ 2. Client Components ('use client'): These are the classic React components we all know and love. They handle useState, useEffect, and DOM events (onClick). I strictly reserve these for the interactive islands of the app—like the actual "Select Seat" toggle or the multi-step checkout form. 🤝 3. The Interleaving Magic: The hardest part for developers to grasp is that you can pass a Server Component as a child to a Client Component. You get the rich, snappy interactivity of a client app, but without forcing the user to download megabytes of unnecessary JavaScript bundle. We are essentially moving back to the old-school server-rendering days, but with a drastically better developer experience. 😉 Have you made the jump to Server Components yet (via Next.js or Remix), or are you still happily riding the traditional SPA wave with Vite? Let’s chat architecture in the comments! 👇 Follow RAHUL VIJAYAN for more. #ReactJS #Nextjs #FrontendArchitecture #WebDevelopment #SoftwareEngineering #WebPerformance #FullStackDeveloper
To view or add a comment, sign in
-
-
Web Development Journey : Day-29 React (Part 3) ✅ Today I explored how to make web pages truly interactive by mastering event handling and the fundamentals of component state in React 🧠💻 I covered: • Handling Click Events and Non-Click Events to capture user interactions • Understanding the Event Object to access detailed information about every interaction • Deep dive into State in React and why it’s the heartbeat of dynamic UIs • Introduction to Hooks and using the useState() hook to manage data within components • Using the callback in set state function for more reliable state updates based on previous values • Building a practical Activity: Create LikeButton to see state in action • Exploring Closure in JS and its critical role in how React functions • Understanding Re-render and how React efficiently updates the DOM Learning daily, improving daily 🚀 Consistency > Motivation 💯 #ReactJS #WebDevelopment #FrontendDevelopment #MERNStack #LearningInPublic #DeveloperJourney #apnacollege #sigma #delta #UIUX #JavaScript #WebDev #Hooks
To view or add a comment, sign in
-
-
🚀 Understanding Functional vs Class Components in React — Simplified! In React, everything revolves around components. But there are two types: 👉 Functional Components 👉 Class Components So… which one should you use? 💡 What are Functional Components? 👉 Simple JavaScript functions that return JSX function Greeting() { return <h1>Hello, React!</h1>; } ✅ Cleaner syntax ✅ Easier to read ✅ Uses Hooks (useState, useEffect) ✅ Preferred in modern React 💡 What are Class Components? 👉 ES6 classes that extend React.Component class Greeting extends React.Component { render() { return <h1>Hello, React!</h1>; } } 👉 Uses lifecycle methods instead of hooks ⚙️ Key Differences 🔹 Functional: Uses Hooks Less boilerplate Easier to maintain 🔹 Class: Uses lifecycle methods More complex syntax Harder to manage state 🧠 Real-world use cases ✔ Functional Components: Modern applications Scalable projects Cleaner architecture ✔ Class Components: Legacy codebases Older React apps 🔥 Best Practices (Most developers miss this!) ✅ Prefer functional components in new projects ✅ Use hooks instead of lifecycle methods ✅ Keep components small and reusable ❌ Don’t mix class and functional patterns unnecessarily ⚠️ Common Mistake 👉 Overcomplicating simple components with classes // ❌ Overkill class Button extends React.Component { render() { return <button>Click</button>; } } 👉 Use functional instead 💬 Pro Insight React today is built around: 👉 Functions + Hooks, not classes 📌 Save this post & follow for more deep frontend insights! 📅 Day 7/100 #ReactJS #FrontendDevelopment #JavaScript #ReactHooks #WebDevelopment #SoftwareEngineering #100DaysOfCode 🚀
To view or add a comment, sign in
-
-
🚨 React vs Vanilla JavaScript: the showdown that could save you weeks of work A: React – a component library that handles UI state, routing and ecosystem tools. It shines for large SPAs, offers reusable pieces and has a massive community. B: Vanilla JavaScript – pure browser language, no extra libraries, runs everywhere and lets you keep payload tiny. My verdict: Vanilla JavaScript wins for most client sites. In the past nine years I’ve built dozens of marketing pages, e‑commerce fronts and dashboards. When the page needs a simple form, a carousel or a dynamic headline, a few lines of native code load instantly and avoid the bundle size of a React build. I only reach for React when the product truly behaves like a single page app with complex state, multiple views and a dedicated development team. ✅ Your turn. A or B? Drop it in the comments. 💡 Check if your next project is overengineered. #ThisOrThat #WebDevelopment #WebDesign #Poll #TechDebate #Developer #JavaScript #ReactJS #Frontend #Coding #Performance #UX #WebPerformance #NoCode #Programming
To view or add a comment, sign in
-
💡 CSR vs SSR — Why this actually matters (real bug I faced in React) Recently, I encountered a small but interesting issue while working on a React project. I was using window.innerHeight to fix a scroll-related bug (triggering logic when the user scrolls down). It worked perfectly in my app… Until I realized something important 👇 👉 This logic would break in Server-Side Rendering (SSR). That made me revisit a fundamental concept: CSR vs SSR 🔹 What is Client-Side Rendering (CSR)? 👉 In CSR, the browser builds the UI How it works: Browser requests a page Server sends a minimal HTML file JavaScript loads React renders the entire UI in the browser Server → HTML (empty) + JS Browser → builds full UI 👉 This is why React apps (CRA/Vite) are called Single Page Applications (SPA) Environment: Runs inside browser 🌐 window, document are available ✅ Pros: Smooth navigation (no reloads) Great for dashboards, internal apps Cons: Slower initial load SEO is weaker 🔹 What is Server-Side Rendering (SSR)? 👉 In SSR, the server builds the UI first How it works: Browser requests a page Server runs React code Generates full HTML Sends ready UI to browser Browser displays instantly React hydrates (adds interactivity) Server → ready HTML Browser → shows immediately → hydration Environment: First run happens on server 🖥️ No browser APIs (window, document) ❌ After hydration → browser takes over ✅ Pros: Faster first load Better SEO Content visible immediately Cons: More complex setup Requires server/framework (like Next.js) ⚠️ The real issue I faced I used: window.innerHeight 👉 Works perfectly in CSR ❌ Breaks in SSR with error: window is not defined ✅ The fix Make sure browser-specific logic runs only on client side: (hydration) useEffect(() => { // safe to use window here }, []); 🎯 Key takeaway Not all JavaScript runs in the browser. Always know where your code executes — server or client. 🚀 Why this matters Prevents production bugs Essential for SEO-based apps (e-commerce, blogs) Important when using frameworks like Next.js Helps you write scalable, reliable code Understanding this small difference can save hours of debugging and make you a better developer. #React #JavaScript #Frontend #WebDevelopment #SSR #CSR #NextJS
To view or add a comment, sign in
-
🚀 Excited to announce the launch of `react-aspirin`! 💊 After dealing with the same recurring React challenges across multiple projects, I decided to build a solution. Today, I'm open-sourcing react-aspirin—a high-performance, completely tree-shakable React utility library designed to literally "cure" common developer headaches. If you've ever struggled with complex state syncing, diagnosing re-renders, or handling web workers natively in React, this library was built exactly for you. ✨ A few of the 42 lightweight hooks & components included: 🔍 `useTrace`: pinpoint exactly *why* your components are re-rendering. 👻 `useGhost` : zero-config, highly-performant form state management. 🚧 `<Guard />`: a declarative Error Boundary with built-in crash reporting. ⚙️ `useWorker`: seamlessly offload heavy calculations to Web Workers directly in JSX. 🎬 `useTransitionState` & `useAutoAnimate`: fluid, zero-config animations. 📡 `usePoll` & `useOnlineEffect`: smart, visibility-aware network polling. …etc Everything is strictly typed with TypeScript, has zero external dependencies, and is incredibly lightweight. 📚 Interactive Documentation: I've built a full documentation website with 100% live, interactive code previews for every single hook: 🔗 https://lnkd.in/gx4iy4th 💻 Try it out: npm i react-aspirin I'd love for the React community to try it out, break it, and let me know your thoughts! Contributions and feedback are incredibly welcome! 👇 🔗 GitHub: https://lnkd.in/gggVaeDB #ReactJS #WebDevelopment #Frontend #TypeScript #JavaScript #OpenSource #ReactHooks #WebPerf #NodeJS
To view or add a comment, sign in
-
-
For a few days, I was working on building a sticky Notes App using Node.js and Express.js, and instead of using plain HTML, I experimented with EJS (Embedded JavaScript templates). While doing that, I noticed some interesting differences between using static HTML and server-side templating with EJS: • With HTML, everything is static and separate • With EJS, I can dynamically render data directly from the backend • Passing variables from Express to views makes the app feel more “real-time” and flexible • Folder structure becomes more organized when separating routes, views, and logic • It feels closer to how real-world backend-driven applications work This project enhanced my understanding of how frontend and backend integrate more seamlessly through the use of templating engines. I would love to hear how others approach structuring Node.js + Express projects with EJS, and if there are any improvements or best practices you would recommend to make this setup more efficient or scalable. #Nodejs #Expressjs #EJS #BackendDevelopment #WebDevelopment #LearningByDoing
To view or add a comment, sign in
-
For the last decade, the Single Page Application (SPA) was the undisputed king of the frontend. We pushed routing, state management, and rendering all the way to the client. It gave us highly interactive apps, but it also gave us a new problem: Massive JavaScript bundles. Now, we are witnessing a massive architectural shift back to the server. With the rise of React Server Components (RSCs) and frameworks heavily pushing SSR (like Next.js, Nuxt, and SvelteKit), the line between frontend and backend is blurring again. But this isn't just a return to the PHP days. It's a hybrid approach. Here is why this shift is taking over: Zero-Bundle-Size Components: We can now render heavy UI components on the server and ship exactly zero JavaScript to the client for those parts. Better Core Web Vitals: Faster First Contentful Paint (FCP) and Time to Interactive (TTI) because the browser isn't waiting to download and parse megabytes of JS before rendering the page. Direct Backend Access: You can securely query your database directly from a frontend component without building a middleman API layer. We are finally separating the interactive parts of our UI from the static parts at a granular level. The learning curve is steep, and the mental model of "where does this code run?" is shifting, but the performance gains for the end-user are undeniable. #FrontendDevelopment #WebDevelopment #ReactJS #JavaScript #WebPerformance #SoftwareEngineering #SSR #SSG #CSR #SAAS
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development