🚀 Day 14 — Understanding Custom Hooks in React Today I learned about Custom Hooks in React. Custom Hooks allow us to reuse logic across multiple components. Instead of repeating the same logic again and again, we can create our own reusable hook. Why use Custom Hooks? • Reusable logic • Cleaner components • Better code organization • Easy to maintain Example: function useCounter() { const [count, setCount] = useState(0); const increment = () => setCount(count + 1); const decrement = () => setCount(count - 1); return { count, increment, decrement }; } Now we can use it in any component: const { count, increment } = useCounter(); Important Points: • Custom hook name must start with "use" • Can use other hooks inside custom hooks • Makes code more reusable This concept helps in building scalable React applications. Still learning and applying in my projects. #ReactJS #FrontendDevelopment #MERNStack #LearningInPublic
React Custom Hooks for Reusable Logic
More Relevant Posts
-
When I first learned React back in 2021, I focused on understanding the basics — components, JSX, and how the Virtual DOM works. At that time, the goal was simple: 👉 Learn how to build UI efficiently Fast forward to today, and my perspective has changed a lot. Now when I work with React in production systems, I think more about: • Performance and unnecessary re-renders • State management patterns at scale • Component architecture for maintainability • API integration and data flow And one big shift recently — AI in development. Tools like GitHub Copilot and LLMs have changed how we write React code: • Faster component generation • Better debugging support • Less time on boilerplate • More focus on system design and performance But interestingly, the fundamentals I learned earlier still matter the most. If you’re starting with React, I wrote this blog back then — it still covers the basics clearly 👇 https://lnkd.in/gtRu3Tuq Curious — how has your approach to React changed over time? #react #frontend #webdevelopment #softwareengineering #ai
To view or add a comment, sign in
-
React System Design – Day 10: Hooks and Their Rules Hooks are the backbone of modern React development. They let us write cleaner, more reusable, and more functional code. But with great power comes great responsibility — and React enforces some strict rules to keep things predictable. The Two Golden Rules of Hooks Only call Hooks at the top level Don’t call them inside loops, conditions, or nested functions. This ensures React can preserve the correct state across re-renders. Only call Hooks from React functions Hooks must be used inside functional components or custom Hooks. Never call them in regular JS functions or class components. Why These Rules Matter They guarantee consistent order of execution. They prevent bugs where state or effects get mismatched. They make debugging and reasoning about components much easier. Commonly Used Hooks useState → Manage local state useEffect → Handle side effects useContext → Share data without prop drilling useReducer → Complex state management useMemo & useCallback → Performance optimizations Takeaway: Mastering Hooks isn’t just about knowing them — it’s about respecting their rules. That’s what makes React apps scalable and maintainable. #React #SystemDesign #Frontend #Hooks #JavaScript #WebDevelopment
To view or add a comment, sign in
-
What Are Hooks in React? (Explained Simply) If you're learning React, you've probably heard about Hooks everywhere. But what exactly are they? Hooks are special functions in React that let you use state and other features inside functional components — without writing class components. Most Used React Hooks 1. useState Used to store and update data in a component. Think of it as: “I want this component to remember something.” 2. useEffect Used for side effects like API calls, timers, or DOM updates. Think of it as: “Do something after render.” 3. useContext Used to share data globally (no prop drilling). Think of it as: “Access global data easily.” 4. useRef Used to reference DOM elements or persist values without re-render. Think of it as: “Directly access or store something without re-render.” 5. useMemo Optimizes performance by memoizing values. Think of it as: “Only recompute when needed.” 6. 🛠️ Custom Hooks Create your own reusable logic. Think of it as: “Write once, reuse everywhere.” Why Hooks Matter? Cleaner code Reusable logic Easier to understand No more complex class components Final Thought Hooks made React simpler, cleaner, and way more powerful. If you're building modern apps, mastering hooks is a must! What’s your favorite React Hook? #ReactJS #WebDevelopment #Frontend #JavaScript #Coding #MERN #100DaysOfCode
To view or add a comment, sign in
-
-
Day 6 — React hooks are either magic or terrifying, depending on the day. Today: mostly magic. useEffect finally makes sense to me. It's for things that happen outside the React world — API calls, timers, subscriptions. The dependency array is not optional. I learned that the hard way with an infinite loop at 11pm. Built a custom hook today — useFetch — that handles loading, error, and data states. Reused it in two components. That reusability feeling is something else. useRef was a surprise. I thought it was just for accessing DOM elements. Turns out it's also for keeping values across renders without triggering re-renders. Subtle but powerful. useMemo and useCallback: don't reach for them immediately. Optimise when you actually have a problem. What hook tripped you up the most when learning React? #reactjs #hooks #webdevelopment #frontenddeveloper
To view or add a comment, sign in
-
🚀 Update: Version 1.2.0 of react-easy-dashboard is now live on NPM! 📈 Milestone Reached: Growth & Updates for react-easy-dashboard! I am thrilled to see the community's response to react-easy-dashboard! Since the last update, the download count has seen a significant jump, and it’s motivating to see other developers integrating this library into their workflows. 🚀 Two weeks ago, I launched my first UI library, and the feedback has been incredible. Based on that, I’ve spent the last few days refactoring the architecture to make it even more developer-friendly. What’s new in v1.2.0? 🛠️ ✅ Dependency Optimization: Moved heavy components like @mui/x-data-grid to peerDependencies. Result? Smaller bundle size and zero version conflicts for the host app! ✅ Enhanced Documentation: Rewrote the entire README with detailed API tables and implementation guides. ✅ Performance Boost: Fine-tuned the CustomeThemeProvider and Layout engine for smoother transitions. ✅ Ecosystem Growth: Added more specialized icons and improved the SettingsDrawer logic. Building this library has been a journey of understanding NPM lifecycle, Semantic Versioning, and Rollup/Vite configurations. Check it out here: https://lnkd.in/dKasVADD GitHub: https://lnkd.in/dE6kUVd5 If you're a React developer looking for a modular dashboard shell, give it a try! Feedback is always welcome. 👇 #ReactJS #NPM #WebDevelopment #MaterialUI #OpenSource #SoftwareEngineering #Javascript #Frontend
To view or add a comment, sign in
-
If I had to learn React from scratch in 2026, here's exactly what I'd do. Week 1-2: JavaScript FIRST Don't touch React yet. Master: Array methods, destructuring, spread operator, arrow functions, async/await Why: 80% of React confusion = JavaScript confusion Week 3-4: React basics only Build 3 simple projects: - Counter app - Form with validation - Fetch API data Learn: Components, Props, useState, useEffect Stop here. Master these first. Week 5-6: One real project Build a dashboard with real API integration, loading states, and routing. This becomes your portfolio anchor. Week 7-8: Level up Add one at a time: - React Router - Custom hooks - Context API Month 3+: Build, build, build Stop tutorials. Clone real apps. Share your progress. **What to skip initially:** ❌ TypeScript ❌ Next.js ❌ Redux ❌ Testing Learn React first. Add these when you understand WHY you need them. The biggest mistake: Trying to learn React, TypeScript, Next.js, and Redux all at once. You end up overwhelmed. The solution: Master React. Then add layers. One thing at a time = faster progress. If you're learning React, what's your biggest struggle? 👇 #React #WebDevelopment #JavaScript #Frontend #LearningToCode
To view or add a comment, sign in
-
I am thrilled to announce the official deployment of my latest frontend project: Recipe Nexus! 🚀🍲 I set out to build more than just a standard CRUD app. I wanted to engineer a professional-grade React application focused heavily on performance, complex state management, and a seamless user experience. Recipe Nexus allows users to discover trending meals, search a massive database for specific cravings, and instantly pull up the most relevant YouTube video tutorials to watch while they cook. Instead of just following a tutorial, I focused on solving real-world frontend challenges: 🧠 Architectural Wins: Advanced Caching Engine: Engineered a custom caching system using sessionStorage and localStorage to drastically reduce API quota usage, speed up load times, and eliminate "refresh amnesia." Seamless Infinite Scrolling: Implemented the IntersectionObserver API from scratch to create a native, app-like infinite scroll, complete with skeleton loaders, pulsing UI states, and precise pagination logic to prevent endless looping. Scroll Position Restoration: Solved the classic Single Page Application (SPA) navigation bug. Built a custom hook that captures and restores the user's exact pixel scroll depth when navigating between the feed and individual recipe views. Unified Data Flow: Replaced prop-drilling with the React Context API and built centralized custom hooks to orchestrate data between the Spoonacular Recipe API and the YouTube Data API v3. 🛠 The Tech Stack: React (Vite) | Tailwind CSS | Context API | REST APIs | Vercel (CI/CD) A huge takeaway from this project was the importance of the "GitHub Flow"—managing feature branches, testing UI edge cases, and pushing to production via Vercel. I would love for you to check it out and let me know your thoughts or feedback! 🔗 Live Project: https://lnkd.in/gwkXMpqZ 💻 GitHub Repo: https://lnkd.in/gcxi_vas #ReactJS #FrontendDevelopment #WebDevelopment #JavaScript #TailwindCSS #SoftwareEngineering #TechPortfolio #Vite #WebDesign
To view or add a comment, sign in
-
🚀 Understanding useMemo vs useCallback in React — Simplified! If you're optimizing React performance, you've probably seen: 👉 useMemo 👉 useCallback They look similar… but solve different problems. 💡 What is useMemo? 👉 Memoizes a value const result = useMemo(() => { return expensiveCalculation(data); }, [data]); ✅ Recomputes only when dependencies change ✅ Avoids expensive recalculations 💡 What is useCallback? 👉 Memoizes a function const handleClick = useCallback(() => { console.log("Clicked"); }, []); ✅ Keeps function reference stable ✅ Prevents unnecessary re-renders ⚙️ Key Difference 🔹 useMemo → returns a value 🔹 useCallback → returns a function 👉 Think of it like: useMemo → “cache result” useCallback → “cache function” 🧠 Why it matters React re-renders can cause: Expensive calculations New function references Unnecessary child re-renders 👉 These hooks help optimize that 🧩 Real-world use cases ✔ useMemo: Heavy calculations Filtering/sorting large data ✔ useCallback: Passing functions to child components Preventing re-renders with React.memo 🔥 Best Practices (Most developers miss this!) ✅ Use only when needed (not everywhere) ✅ Combine with React.memo for optimization ✅ Keep dependencies accurate ❌ Don’t overuse (can hurt performance) ⚠️ Common Mistake // ❌ Overusing memoization const value = useMemo(() => count + 1, [count]); 👉 Not needed for simple calculations 💬 Pro Insight 👉 useMemo = Optimize computation 👉 useCallback = Optimize re-renders 📌 Save this post & follow for more deep frontend insights! 📅 Day 15/100 #ReactJS #FrontendDevelopment #JavaScript #ReactHooks #PerformanceOptimization #SoftwareEngineering #100DaysOfCode 🚀
To view or add a comment, sign in
-
-
𝐑𝐞𝐚𝐜𝐭 𝐯𝐬 𝐀𝐧𝐠𝐮𝐥𝐚𝐫: 𝐍𝐨𝐭 𝐚 𝐓𝐨𝐨𝐥 𝐂𝐡𝐨𝐢𝐜𝐞 — 𝐀 𝐓𝐡𝐢𝐧𝐤𝐢𝐧𝐠 𝐒𝐡𝐢𝐟𝐭 I’ve been exploring React alongside my experience with Angular. 𝗪𝗵𝗮𝘁 𝘀𝘁𝗼𝗼𝗱 𝗼𝘂𝘁 𝘄𝗮𝘀𝗻’𝘁 𝘀𝘆𝗻𝘁𝗮𝘅 𝗼𝗿 𝗔𝗣𝗜𝘀 - it is the difference in how each approach shapes UI design decisions. 1. Angular provides a well-defined structure that guides consistency at scale. 2. React, in contrast, shifts that responsibility to the developer through composition. This isn’t just a tooling difference — it directly impacts how you think about: a. Component boundaries b. State management c. Codebase maintainability ▪️ Opinionated vs flexible ▪️ Convention-driven vs composition-driven Neither is better by default — the real difference shows when our codebase and team start to scale. Flexibility is powerful — but it demands stronger discipline as systems grow. I’ve started applying these ideas in a small project here: https://lnkd.in/gFBu9rd7 Early observations, but already a useful reminder — the tools we use don’t just affect implementation, they shape how we think about building solutions. More as I explore further 🚀
To view or add a comment, sign in
-
By default, React is fast. But as data grows, unnecessary re-renders quietly kill performance. Today I learned two hooks that every serious React developer needs to know: 🗒️ useMemo — A cache for heavy calculations. Instead of re-running expensive logic on every render, React stores the result and reuses it. Think of it like a sticky note your genius friend writes so they don't have to solve the same problem twice. 🔗 useCallback — Stabilizes your functions. In JS, functions are objects — so a "new" one gets created on every render. This hook keeps the reference the same, stopping child components from re-rendering for no reason. The senior wisdom I picked up today? Don't over-optimize. These hooks cost memory. Only reach for them when you actually see a lag — not before. Understanding when to optimize is what separates professional developers from the rest. Tomorrow: I'm building my own tools with Custom React Hooks! 👀 Question for you: Do you optimize as you go, or wait until something feels slow? Drop your strategy below 👇 #CodeWithWajid #ReactJS #WebDevelopment #100DaysOfCode #LearningToCode #BuildingInPublic #ReactOptimization #WebPerf
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