SK— useRef (Build a Timer) 💡 Explanation: useRef holds values without causing re-renders. Great for timers, intervals & DOM elements. 🧩 Example: Timer function Timer() { const timerRef = useRef(null); const [seconds, setSeconds] = useState(0); const start = () => { timerRef.current = setInterval(() => setSeconds(s => s + 1), 1000); }; const stop = () => clearInterval(timerRef.current); return ( <> <h2>{seconds}s</h2> <button onClick={start}>Start</button> <button onClick={stop}>Stop</button> </> ); } 💬 Question: Have you ever used useRef to store previous values? 📌 Follow Sasikumar S for daily React reflections, dev career insights & coding inspiration. 🤝 Connect Now: sasiias2024@gmail.com 💟 Visit: sk-techland.web.app ❤️ Follow our LinkedIn Page for more React, JavaScript & software engineering growth. #ReactJS #WebDevelopment #FrontendDeveloper #JavaScript #SystemDesign #CodingJourney #SoftwareEngineering #ErrorHandling #GitFlow #ReactProjectStructure #CareerGrowth #MockInterview #TechLearning #ProblemSolving #DeveloperMindset
How to Build a Timer with useRef in React
More Relevant Posts
-
📍 SK — Reusable Component Patterns 💡 Explanation Reusable components reduce repetition and increase maintainability. A reusable component should be generic, configurable, and stateless as much as possible. 🧩 Example: Reusable Button Component export default function Button({ children, variant = "primary", onClick }) { const base = "px-4 py-2 rounded-md font-medium"; const styles = { primary: base + " bg-blue-600 text-white", outline: base + " border border-blue-600 text-blue-600" }; return <button className={styles[variant]} onClick={onClick}>{children}</button>; } // Usage: <Button variant="outline">Add to Cart</Button> 💬 Question Which component do you find yourself rewriting most often? (Button, Modal, Card, Input?) 📌 Follow Sasikumar S for daily React reflections, dev career insights & coding inspiration. 🤝 Connect Now: sasiias2024@gmail.com 💟 Visit: sk-techland.web.app ❤️ Follow our LinkedIn Page for more React, JavaScript & software engineering growth. #ReactJS #WebDevelopment #FrontendDeveloper #JavaScript #SystemDesign #CodingJourney #SoftwareEngineering #ErrorHandling #GitFlow #ReactProjectStructure #CareerGrowth #MockInterview #TechLearning #ProblemSolving #DeveloperMindset
To view or add a comment, sign in
-
-
SK — createAsyncThunk (Async Calls) 💡 Explanation: createAsyncThunk helps handle async logic like API calls and automatically manages pending, fulfilled, and rejected states. 🧩 Example import { createAsyncThunk } from "@reduxjs/toolkit"; export const fetchProducts = createAsyncThunk( "products/fetch", async () => { const res = await fetch("https://lnkd.in/g6BEwS7k"); return res.json(); } ); 💬 Question: Do you manage loading & error states manually or rely on createAsyncThunk lifecycle actions? 📌 Follow Sasikumar S for daily React reflections, dev career insights & coding inspiration. 🤝 Connect Now: sasiias2024@gmail.com 💟 Visit: sk-techland.web.app ❤️ Follow our LinkedIn Page for more React, JavaScript & software engineering growth. #ReactJS #WebDevelopment #FrontendDeveloper #JavaScript #SystemDesign #CodingJourney #SoftwareEngineering #ErrorHandling #GitFlow #ReactProjectStructure #CareerGrowth #MockInterview #TechLearning #ProblemSolving #DeveloperMindset #redux
To view or add a comment, sign in
-
-
Today I implemented a Mount Timer using React class components to better understand how lifecycle methods behave during state changes. What this component does: Initializes state with seconds and a dynamic count threshold Uses componentDidMount() to start a setInterval timer that increments every second Uses componentDidUpdate() to detect when seconds reaches the current threshold and automatically updates the next milestone (5s → 10s → 15s…) Cleans up the interval in componentWillUnmount() to prevent memory leaks Demonstrates how continuous state updates trigger re-render cycles Why I built this: To get hands-on clarity on how React handles: Mounting vs. Updating phases State mutation inside lifecycle methods Cleanup logic Re-render behavior and async state updates Attached video shows: ->The full source code -> Step-by-step output -> Lifecycle events in real-time Always sharpening fundamentals — React is powerful when you deeply understand its lifecycle. Trainer : Ms. Meghana Meghana M 10000 Coders #ReactJS #JavaScript #FrontendEngineering #TechLearning #WebDevelopment #CleanCode
To view or add a comment, sign in
-
#java day 27 questions 🟩 Day 27 – React Forms + Validation with Hooks (English, #Tech27) Capture, control, and validate user input with modern React form patterns and hook-based logic --- 🔹 Form Handling Basics - How do you create a controlled form in React? - What is the difference between controlled and uncontrolled components? - How do you use useState to manage form input values? - How do you handle form submission in React? --- 🔹 Input Management - How do you bind input fields to state variables? - How do you handle multiple form fields dynamically? - How do you reset form values after submission? - How do you manage checkbox, radio, and select inputs? --- 🔹 Validation Techniques - What are common validation rules for form inputs? - How do you implement basic validation using conditional rendering? - How do you show error messages dynamically? - How do you disable the submit button until the form is valid? --- 🔹 Advanced Form Handling - How do you use useEffect to validate fields on change? - How do you integrate third-party libraries like Formik or React Hook Form? - What is the benefit of schema-based validation with Yup? - How do you handle async validation (e.g., checking username availability)? --- 🔹 Practice Tasks - ✅ Build a contact form with name, email, and message fields - ✅ Use useState to manage input and validation state - ✅ Show error messages for empty or invalid fields - ✅ Disable submit button until all fields are valid - ✅ Reset form after successful submission - ✅ Push the project to GitHub with README and screenshots ReactJS #Forms #FormValidation #ReactHooks #useState #useEffect #ControlledComponents #Tech27 #FrontendDevelopment #JavaScript #FullStack #UIDevelopment #DigitalIndia #NamasteBharat #StructuredLearning #75Modules #18Phases #PrintReady #GitHubShowcase #LinkedInReady #CodeToInspire #DeveloperMindset #OpenToWork #TechHiring #CareerInTech #ReactMastery #Formik #ReactHookForm #YupValidation #LegacyDriven `
To view or add a comment, sign in
-
🗓️ SK - 3 – React Hooks (Deep Dive) 🪝 🎯 Goal: Master React Hooks — the heart of modern React development. 🧠 Core Topics ✅ useState, useEffect, useContext, useReducer ✅ useMemo, useCallback, useRef ✅ Custom Hooks for reusability 💻 Coding Practice ⚙️ Create a custom hook for fetching data from an API. ⚙️ Use useMemo and useCallback to optimize renders. ⚙️ Build a stopwatch using useRef. 🎥 Learning Resources 🔗 React Hooks Tutorial – Net Ninja 🔗 useEffect Deep Dive – Codevolution 💬 Mock Interview Prep ❓ When does useEffect run? ❓ What’s the difference between useMemo and useCallback? ❓ How do you share logic between components using custom hooks? 🌟 Reflection: Hooks aren’t just syntax — they’re a paradigm shift. They make React code more readable, modular, and powerful. Every time you replace a class lifecycle with a clean useEffect, you write smarter code. ⚙️ Mastering Hooks = mastering React’s functional mindset. Write less. Do more. Think declaratively. 💡 💬 Which React Hook do you use the most in your projects? Comment below 👇 📌 Follow Sasikumar S for daily React insights, code challenges & growth reflections. 🤝 Connect Now: sasiias2024@gmail.com 💟 Visit: sk-techland.web.app ❤️ Follow our LinkedIn Page for more React & JavaScript wisdom. #ReactJS #ReactHooks #WebDevelopment #FrontendDeveloper #useEffect #useState #CustomHooks #JavaScript #CodingJourney #Optimization #CleanCode #SoftwareEngineering #CareerGrowth #TechLearning
To view or add a comment, sign in
-
⚡ SK – Event Loop & Callback Queue: The Heart of JavaScript Execution 💡 Explanation (Clear + Concise) The event loop allows JavaScript to perform non-blocking I/O operations — executing callbacks after the main stack is clear. 🧩 Real-World Example (Code Snippet) console.log("1️⃣ Start"); setTimeout(() => console.log("3️⃣ Timeout callback"), 0); Promise.resolve().then(() => console.log("2️⃣ Promise resolved")); console.log("4️⃣ End"); // Output: // 1️⃣ Start // 4️⃣ End // 2️⃣ Promise resolved // 3️⃣ Timeout callback ✅ Why It Matters in React: Helps understand asynchronous rendering & useEffect timing. Crucial for optimizing performance and debugging async issues. 💬 Question: Have you ever faced a tricky bug due to async behavior in React? How did you debug it? 📌 Follow Sasikumar S for more daily dev reflections, real-world coding insights & React mastery. 🤝 Connect Now: sasiias2024@gmail.com 💟 Visit: sk-techland.web.app ❤️ Follow our LinkedIn Page for more React & JavaScript growth tips. #JavaScript #ReactJS #EventLoop #FrontendDeveloper #AsyncCode #JSFundamentals #WebPerformance
To view or add a comment, sign in
-
-
𝐍𝐨𝐝𝐞.𝐣𝐬 𝐁𝐞𝐬𝐭 𝐏𝐫𝐚𝐜𝐭𝐢𝐜𝐞𝐬 𝐃𝐨’𝐬 & 𝐃𝐨𝐧’𝐭𝐬 In modern JavaScript development, writing clean and efficient async code is crucial for scalability and performance. ✅ The correct way is to use async/await inside functions, ensuring proper error handling and execution flow. ❌ A common mistake developers make is using forEach with async/await. Since forEach doesn’t wait for promises to resolve, it often leads to unexpected behavior. Instead, consider using for...of loops or Promise.all when working with async operations in arrays. 𝐈 𝐛𝐞𝐥𝐢𝐞𝐯𝐞 𝐦𝐚𝐬𝐭𝐞𝐫𝐢𝐧𝐠 𝐭𝐡𝐞𝐬𝐞 𝐬𝐦𝐚𝐥𝐥 𝐝𝐞𝐭𝐚𝐢𝐥𝐬 𝐦𝐚𝐤𝐞𝐬 𝐚 𝐛𝐢𝐠 𝐝𝐢𝐟𝐟𝐞𝐫𝐞𝐧𝐜𝐞 𝐢𝐧 𝐛𝐮𝐢𝐥𝐝𝐢𝐧𝐠 𝐫𝐞𝐥𝐢𝐚𝐛𝐥𝐞 𝐚𝐧𝐝 𝐩𝐫𝐨𝐝𝐮𝐜𝐭𝐢𝐨𝐧 𝐫𝐞𝐚𝐝𝐲 𝐍𝐨𝐝𝐞.𝐣𝐬 𝐚𝐩𝐩𝐥𝐢𝐜𝐚𝐭𝐢𝐨𝐧𝐬. #Nodejs #JavaScript #Programming #CleanCode #BinteHawa
To view or add a comment, sign in
-
-
🌱 𝗗𝗮𝘆 77 | 𝗨𝗻𝗱𝗲𝗿𝘀𝘁𝗮𝗻𝗱𝗶𝗻𝗴 𝗥𝗲𝗰𝘂𝗿𝘀𝗶𝗼𝗻 𝗧𝗿𝗲𝗲𝘀 & 𝗛𝗮𝗻𝗱𝘀-𝗼𝗻 React 𝗣𝗿𝗮𝗰𝘁𝗶𝗰𝗲 🌱 Today’s learning was a perfect mix of 𝗗𝗦𝗔 𝗹𝗼𝗴𝗶𝗰 𝗮𝗻𝗱 𝗥𝗲𝗮𝗰𝘁 𝗽𝗿𝗮𝗰𝘁𝗶𝗰𝗲𝗅 💻 🧠 𝗜𝗻 𝗗𝗦𝗔: I studied about 𝗥𝗲𝗰𝘂𝗿𝘀𝗶𝗼𝗻 𝗧𝗿𝗲𝗲𝘀 — how recursive calls expand like a tree structure, helping visualize and analyze 𝘁𝗶𝗺𝗲 𝗰𝗼𝗺𝗽𝗹𝗲𝘅𝗶𝘁𝘆 and 𝗳𝘂𝗻𝗰𝘁𝗶𝗼𝗻 𝗰𝗮𝗹𝗹𝘀. ⚛️ 𝗜𝗻 𝗥𝗲𝗮𝗰𝘁: I did some 𝗵𝗮𝗻𝗱𝘀-𝗼𝗻 𝗽𝗿𝗮𝗰𝘁𝗶𝗰𝗲 with: - 𝗙𝗼𝗿𝗺𝘀 𝗮𝗻𝗱 𝗟𝗶𝘀𝘁𝘀 (handling user input and rendering data dynamically) - 𝗔𝗣𝗜 𝗙𝗲𝘁𝗰𝗵𝗶𝗻𝗴 using sample data from Lorem Ipsum for practice Every small project and concept I explore adds a new layer of confidence to my developer journey! 🚀 #Day77 #Recursion #DSA #ReactJS #FrontendDevelopment #WebDevelopment #JavaScriptDeveloper #LearningInPublic #CodingJourney #100DaysOfCode #APIFetch #ReactForms #ReactLists #SoftwareEngineer #FullStackDeveloper #DeveloperGrowth #CodingLife #BuildInPublic #TechLearning #ProblemSolving #OpenToWork #CareerGrowth
To view or add a comment, sign in
-
⚡ SK – Destructuring & Spread/Rest Operators: Simplifying Your JavaScript Code 💡 Explanation (Clear + Concise) Destructuring and spread/rest operators make your JavaScript code cleaner, shorter, and more readable — by unpacking or combining data from arrays and objects efficiently. 🧩 Real-World Example (Code Snippet) // 🧱 Object Destructuring const user = { name: "Sasi", role: "React Developer", city: "Chennai" }; const { name, role } = user; console.log(`${name} works as a ${role}`); // Sasi works as a React Developer // 🔁 Array Destructuring const skills = ["React", "Redux", "TypeScript"]; const [primarySkill, , extraSkill] = skills; console.log(primarySkill, extraSkill); // React TypeScript // 🚀 Spread Operator (copy or merge) const devDetails = { ...user, country: "India" }; // 🧩 Rest Operator (group remaining) const { city, ...profile } = user; console.log(profile); // { name: 'Sasi', role: 'React Developer' } ✅ Why It Matters in React: Extract props and state easily: const { title, price } = product; Pass data without mutating: setUser({ ...user, loggedIn: true }); 💬 Question: What’s one place in your recent React project where destructuring made your code cleaner? 📌 Follow Sasikumar S for more daily dev reflections, real-world coding insights & React mastery. 🤝 Connect Now: sasiias2024@gmail.com 💟 Visit: sk-techland.web.app ❤️ Follow our LinkedIn Page for more React & JavaScript growth tips. #JavaScript #ReactJS #ES6 #FrontendDeveloper #CodingJourney #WebDevelopment #JSFundamentals #TechLearning #CareerGrowth #CodeTips
To view or add a comment, sign in
-
-
I’ve just finished the final lecture of #NamasteJavaScript series by Akshay Saini 🚀 , where he explained the this keyword along with several other important concepts. 🌍 1. Global Space In global scope, this refers to the global object (window in browsers, global in Node.js). Represents the global environment — used when a function isn’t tied to any object. ⚙️ 2. Function Scope The value of this depends on how a function is called. In regular functions → refers to the object that called the function. If no object calls it → defaults to the global object (in non-strict mode). 🧠 3. Strict vs Non-Strict Mode Strict mode: this becomes undefined if not explicitly defined — safer and more predictable. Non-strict mode: defaults to the global object, which can cause unexpected behavior. 🧩 4. Object Methods — call(), apply(), bind() call() → Calls function immediately, passing this and arguments individually. apply() → Same as call, but takes arguments as an array. bind() → Returns a new function with a fixed this value (not called immediately). 🏹 5. Arrow Functions Arrow functions don’t have their own this — they inherit it from their surrounding scope. Perfect for callbacks and nested functions. 🏗️ 6. this in the DOM In event handlers, this refers to the HTML element that triggered the event. "A heartfelt thanks to Akshay Saini 🚀 sir for JavaScript series — truly grateful for your clear explanations and dedication!" #JavaScript #WebDevelopment #Programming #CleanCodeAlways #JavaScript #CleanCode #SoftwareEngineering #DevNotes #DevLife #FrontendDeveloper #linkedinlearning #LearningJourney #CareerGrowth #CodeSmarter #NamasteJavaScript #Akshaysaini #thiskeyword
To view or add a comment, sign in
-
Explore related topics
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
Great post! useRef is indeed invaluable for managing timers and preserving values without re-renders. Looking forward to more insights on React and development techniques!