Day 35: Utility function revision. Reviewing the utility functions I have built over the past few weeks. The goal was to move away from writing logic inside components and instead build a modular library of reusable helpers. Refactoring these small functions highlighted a few key principles: Separation of concerns: Keeping business logic separate from helper logic makes the codebase easier to test and maintain. Input validation: Adding default parameters and type checks ensures that utilities do not break when encountering null or undefined values. DRY principle: Identifying patterns in my previous code allowed me to consolidate multiple similar functions into single, flexible utilities. #JavaScript #WebDevelopment #CleanCode #Frontend #CodingJourney #UtilityFunction
Refactoring Utility Functions for Separation of Concerns
More Relevant Posts
-
Most bugs in production don’t come from complex systems... 💻 They come from simple misunderstandings. Here’s one that even experienced developers occasionally get wrong 👇 🧠 Three snippets. Same intention. Different behavior. // 1 function logValue(value) { if (value === 2) return; console.log(value) } for (let i = 1; i < 5; i++) { logValue(i) } // 2 for (let i = 1; i < 5; i++) { if (i === 2) return; console.log(i) } // 3 [1,2,3,4].forEach((num) => { if (num === 2) return console.log(num) }) 🔍 What’s actually happening? Snippet 1 → Safe abstraction return exits only the function Loop continues Output: 1, 3, 4 Snippet 2 → Dangerous assumption return exits the entire enclosing function Loop stops completely at 2 Output: 1 👉 If this is inside a React component or handler → you just aborted execution. Snippet 3 → Misleading familiarity return exits only the callback, not the loop forEach keeps iterating Output: 1, 3, 4 💡 Takeaway Control flow is not about syntax - it's about execution boundaries. Ask yourself: “What exactly am I returning from?” Function? Loop? Callback? Component? Because JavaScript won’t warn you. It will just… behave correctly in a way you didn’t expect. 🧩 Rule of thumb return in functions → exits function return in forEach → skips current iteration return in loops (top-level) → exits enclosing function (not just loop) The code looks similar. The runtime behavior is not. And that difference is where real-world bugs live. #javascript #reactjs #webdevelopment #softwareengineering #frontend #cleanCode
To view or add a comment, sign in
-
-
Day 23 #100DaysOfCode 💻 #React #Module_39 1. Why is component-based architecture useful in React applications? = It allows reusable and organized UI components. 2. Which tool is used to manage states globally in React? = Redux (or Context API). 3. What is the purpose of the useEffect hook? = To handle side effects like data fetching, subscriptions, or manually changing the DOM. 4. In React, what is "JSX"? = A syntax extension that allows writing HTML-like code within JavaScript. 5. What is the use of "props" in React? = To pass data and event handlers from a parent component to a child component. 6. What is the Virtual DOM? = A lightweight representation of the real DOM that React uses to optimize updates and improve performance. 7. Which hook is used to manage local state in a functional component? = useState. 8. What is a "Higher-Order Component" (HOC)? = A function that takes a component and returns a new component with enhanced functionality. 9. How do you handle events in React? = Using camelCase syntax (e.g., onClick) and passing a function as the event handler. 10. What is the purpose of "Keys" in React lists? = To provide a stable identity to list elements, helping React identify which items have changed, been added, or removed.
To view or add a comment, sign in
-
Most "reusable" components are actually technical debt in disguise. After building interfaces for systems managing over €𝟲𝗕 in assets and leading "0 to 1" product builds, I’ve learned that the most maintainable code isn’t the most abstract. It’s the most flexible. I don't like very long articles, so I'll keep this short. Here are 3 senior-level patterns to ensure your React codebase scales without collapsing under its own weight: 𝟭. 𝗜𝗻𝘃𝗲𝗿𝘀𝗶𝗼𝗻 𝗼𝗳 𝗖𝗼𝗻𝘁𝗿𝗼𝗹 (𝗖𝗼𝗺𝗽𝗼𝘀𝗶𝘁𝗶𝗼𝗻 > 𝗣𝗿𝗼𝗽𝘀) Stop adding boolean props like hasIcon, isLarge, or withTooltip. This creates a "MegaComponent" that is impossible to test. 𝗧𝗵𝗲 𝗙𝗶𝘅: Use the Render Props or Compound Components pattern. Pass the icon or tooltip as a child. Let the parent control the "what" while the component controls the "how." 𝟮. 𝗧𝗵𝗲 "𝗟𝗼𝗴𝗶𝗰-𝗙𝗿𝗲𝗲" 𝗨𝗜 𝗟𝗮𝘆𝗲𝗿 If your UI component contains complex data fetching or business logic, it’s not truly reusable. 𝗧𝗵𝗲 𝗙𝗶𝘅: Move logic into Custom Hooks. A useUserDashboard hook should handle the state and TanStack Query logic, leaving your component to focus strictly on the view. This makes unit testing logic 10x faster. 𝟯. 𝗦𝘁𝗿𝗶𝗰𝘁 𝗧𝘆𝗽𝗲 𝗡𝗮𝗿𝗿𝗼𝘄𝗶𝗻𝗴 𝘄𝗶𝘁𝗵 𝗧𝘆𝗽𝗲𝗦𝗰𝗿𝗶𝗽𝘁 Avoid 𝗮𝗻𝘆 or overly broad interfaces. 𝗧𝗵𝗲 𝗙𝗶𝘅: Use Discriminated Unions for component variants. If a Notification component can be either 'Success' or 'Error', ensure the props reflect that strictly. This prevents "impossible states" (like a success message with an error icon) from ever reaching production. 𝗧𝗵𝗲 𝗚𝗼𝗹𝗱𝗲𝗻 𝗥𝘂𝗹𝗲: High-quality code isn't just about DRY (Don't Repeat Yourself); it's about being easy to delete and replace. #ReactJS #TypeScript #WebArchitecture #FrontendEngineering #CleanCode #SeniorDeveloper
To view or add a comment, sign in
-
-
Built a Blog Manager using Vanilla JavaScript with multiple real-world features. This project includes CRUD functionality (create, edit, delete), localStorage for data persistence, markdown support for rich content, image rendering, and a tag system with real-time filtering. Also focused on clean modular architecture by separating data, UI, and logic. JASIQ Labs Live Demo: https://lnkd.in/g7vf9_AD GitHub: https://lnkd.in/gsaV5BPB Working on this helped me understand how frontend applications are structured and managed without using frameworks. #javascript #frontend #webdevelopment #learning
To view or add a comment, sign in
-
I recently ran into a production bug that didn’t make sense at first. The code looked correct. The logic was sound. And yet… execution order was completely off. After digging deeper, the issue wasn’t the code itself — it was how the browser was scheduling it. That’s when I had to go back to fundamentals: the Event Loop. At the core of browser execution are 4 moving parts: 🔹 Call Stack – synchronous execution 🔹 Web APIs – timers, network, DOM events 🔹 Task Queue – macrotasks 🔹 Microtask Queue – Promises, MutationObserver 🎯 The root cause? A Promise callback was executing before a timer-based callback — even though the timer had 0 delay. Because: 👉 All microtasks run before the next macrotask. That small detail caused a race condition where state was being updated earlier than expected — breaking the flow. 💡 Fixing it required: • Rethinking execution order (not just code order) • Moving critical logic into the correct queue • Ensuring state updates aligned with the event loop cycle This wasn’t just a “bug fix” — it was a reminder: 🔁 If something feels off in async JavaScript, don’t just debug the code — debug the event loop. Once you see it, everything clicks. --- ♻️ Repost if you’ve ever chased a “ghost bug” in async JS 💬 Comment: What’s the trickiest async issue you’ve debugged? #JavaScript #EventLoop #AsyncProgramming #WebDevelopment #Frontend #SoftwareEngineering #Coding #Debugging #JS #WebPerformance #Developers
To view or add a comment, sign in
-
-
𝗜 𝗺𝗮𝗱𝗲 𝗺𝘆 𝗰𝗼𝗱𝗲 𝘄𝗼𝗿𝗸... 𝗯𝘂𝘁 𝗻𝗼𝘁 𝗺𝗮𝗶𝗻𝘁𝗮𝗶𝗻𝗮𝗯𝗹𝗲. While working on one of my projects, I decided to move to Appwrite. Initially, I directly used the documentation and plugged the code inside components without thinking much about structure. It worked… until I had to make changes. Shifting things later became messy and difficult to manage. That’s when I realized the problem wasn’t the tool, it was how I structured my code. So I refactored with a better approach: ➯Introduced a Service Wrapper layer to encapsulate all business logic ➯Kept the rest of the application decoupled from the backend provider ➯Centralized configuration and initialization instead of scattering it across components ➯Ensured resources are used efficiently by initializing only when needed ➯Exposed a clean, single interface for the rest of the app to interact with This made the codebase much easier to maintain and flexible enough to switch services in the future if needed. #softwareengineering #webdevelopment #architecture #cleancode #javascript #buildinpublic #developers
To view or add a comment, sign in
-
Are You Using Hooks or Misusing Them? Hooks made React cleaner but only if you respect the rules. In production environments, most bugs don't stem from complex business logic; they stem from subtle anti-patterns that degrade performance and scalability. If you’re aiming for senior-level code, here are the patterns you should stop today: ⚠️ 1. The useEffect Crutch If a value can be computed during render, it doesn’t belong in an effect. Effects are for synchronization with external systems, not for transforming data. Overusing them leads to unnecessary re-renders and "race condition" bugs. ⚠️ 2. Suppressing Dependency Arrays Disabling ESLint warnings is like ignoring a "Check Engine" light. If including a dependency breaks your logic, your logic is flawed, not the rule. Fix the stale closure; don't hide it. ⚠️ 3. Storing Derived State Storing data in useState that can be calculated from props or other state variables is a recipe for sync issues. Always maintain a Single Source of Truth. ⚠️ 4. Abstraction Fatigue (Custom Hook Overkill) Not every 3-line logic block needs a custom hook. Premature abstraction often makes code harder to follow than simple, localized duplication. Abstract for reusability, not just for "cleaner" looking files. ⚠️ 5. Using Hooks to Mask Architectural Debt Hooks are powerful, but they won't fix a poorly structured component tree. Clean architecture > "Clever" hook implementations. 💡 Senior Dev Mindset: Hooks are not just features; they are constraints that enforce predictable behavior. If your React codebase feels "fragile," it’s rarely a React problem it's usually a Hook implementation problem. 💬 Curious to hear from the community: Which of these "subtle" bugs have you spent the most time debugging lately? #ReactJS #FrontendArchitecture #WebDevelopment #JavaScript #SoftwareEngineering #CleanCode #ReactHooks #SeniorDeveloper #CodeQuality #ProgrammingTips
To view or add a comment, sign in
-
Promise.resolve vs new Promise — one of the most confusing concepts in JavaScript I simplified it with real examples + clear rules. Read here 👇 https://lnkd.in/dZPSdvJh #JavaScript #AsyncJS #WebDevelopment
To view or add a comment, sign in
-
Evolving React Architecture from Context to Service Layer Today, I took a step toward senior-level React architecture by refactoring my state management logic. Instead of letting a "God Context" handle everything, I introduced a Service Layer for data persistence. By abstracting localStorage logic into a dedicated storage service, I’ve achieved: 1- Decoupled UI & Data: My components no longer care how data is stored. 2- Easier Scaling: Switching from LocalStorage to a real API now only requires touching one file. 3- Clean Code: My Context files are leaner and easier to maintain. Senior-level development isn't just about making things work—it’s about making things scale. #ReactJS #WebDevelopment #SoftwareArchitecture #CleanCode #JavaScript
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