𝗦𝘁𝗼𝗽 𝗺𝗮𝗸𝗶𝗻𝗴 𝗰𝘂𝘀𝘁𝗼𝗺 𝗵𝗼𝗼𝗸𝘀 𝗳𝗼𝗿 𝗲𝘃𝗲𝗿𝘆𝘁𝗵𝗶𝗻𝗴 Early in my React journey, I treated custom hooks like a badge of honor. If there was state, I extracted it. If there was logic, I wrapped it. useToggle for a boolean. useCounter for a number. useForm for every input. useFetch for every API call. useLocalStorage for a single value. I was abstracting anything that moved. My /hooks folder was massive. And I thought that meant my code was clean. It wasn't. It was overengineered. Premature abstraction is just as dangerous as premature optimization. A custom hook that wraps a single useState adds zero value. It adds a layer of indirection. It adds a file to navigate. It adds cognitive load for anyone reading your code, including future you. `const [isOpen, setIsOpen] = useState(false)` doesn't need a useToggle hook. It's already clear. It's already simple. Leave it alone. The principle that changed how I think about abstractions: don't abstract until you have to. Duplication is far cheaper than the wrong abstraction. I now have three clear criteria for when a custom hook earns its place: The logic is shared across 3+ components. Not 2, not "maybe later." Three or more, with actual duplication happening right now. It encapsulates a third-party library, so the rest of the application doesn't couple directly to that dependency. It contains business logic that needs to be tested in isolation from the component layer. If it doesn't meet at least one of these criteria, it stays inline. The result? Fewer files. Fewer abstractions. Code that's easier to read, easier to debug, and easier to hand off to another developer. Junior developers abstract to look smart. Senior developers keep things simple because they've seen the cost of not doing so. Write the useState. Inline the logic. Extract only when the codebase demands it, not when your instincts suggest it. Simplicity isn't lazy. It's a skill. #React #JavaScript #TypeScript #WebDevelopment #Frontend #SoftwareEngineering
Christopher Okafor’s Post
More Relevant Posts
-
Most messy React code isn’t caused by complexity. It’s caused by ignoring 𝐛𝐚𝐬𝐢𝐜 𝐜𝐨𝐦𝐩𝐨𝐧𝐞𝐧𝐭 𝐚𝐧𝐚𝐭𝐨𝐦𝐲. Learning the "blueprint" of a React component changes the game. Once you get how it’s built, your code makes more sense, you’ll spend less time fixing mistakes, and it’s much easier for your team to understand your work. Why it matters: 𝐂𝐥𝐞𝐚𝐧𝐞𝐫 𝐋𝐨𝐠𝐢𝐜: You know exactly where your data should go. 𝐅𝐞𝐰𝐞𝐫 𝐇𝐞𝐚𝐝𝐚𝐜𝐡𝐞𝐬: It’s harder to break things when you follow the right pattern. 𝐁𝐞𝐭𝐭𝐞𝐫 𝐓𝐞𝐚𝐦𝐰𝐨𝐫𝐤: Everyone is finally speaking the same "code language." A clean React component typically follows this order: 1️⃣ **𝐢𝐦𝐩𝐨𝐫𝐭 𝐬𝐭𝐚𝐭𝐞𝐦𝐞𝐧𝐭𝐬** – External libraries, hooks, and child components. Keep them organized and intentional. 2️⃣ **𝐂𝐨𝐦𝐩𝐨𝐧𝐞𝐧𝐭 𝐝𝐞𝐟𝐢𝐧𝐢𝐭𝐢𝐨𝐧** – The functional component itself. This is your boundary and responsibility unit. 3️⃣ **𝐕𝐚𝐫𝐢𝐚𝐛𝐥𝐞 𝐝𝐞𝐜𝐥𝐚𝐫𝐚𝐭𝐢𝐨𝐧𝐬** – Derived values, constants, and computed data. Keep them close to where they’re used. 4️⃣ **𝐡𝐨𝐨𝐤 𝐜𝐚𝐥𝐥𝐬** – `useState`, `useEffect`, and custom hooks. Always at the top level, never conditionally. 5️⃣ **𝐋𝐨𝐜𝐚𝐥 𝐟𝐮𝐧𝐜𝐭𝐢𝐨𝐧𝐬** – Event handlers and helper functions. Keep them focused and readable. 6️⃣ **𝐑𝐞𝐧𝐝𝐞𝐫𝐞𝐝 𝐜𝐨𝐧𝐭𝐞𝐧𝐭 (JSX)** – The UI representation of your logic. Clean, minimal, and declarative. When this order is respected, components become predictable and easier to refactor. Here’s how to apply this immediately: ✔ Follow a consistent top-to-bottom structure in every component ✔ Separate logic (hooks/functions) from JSX visually ✔ Extract complex sections into smaller reusable components 𝐑𝐞𝐚𝐜𝐭 𝐟𝐚𝐯𝐨𝐫𝐬 𝐝𝐢𝐬𝐜𝐢𝐩𝐥𝐢𝐧𝐞 𝐨𝐯𝐞𝐫 𝐢𝐦𝐩𝐫𝐨𝐯𝐢𝐬𝐚𝐭𝐢𝐨𝐧. When reviewing your components, does their structure help readability—or fight against it? #ReactJS #FrontendArchitecture #ComponentDesign #JavaScript #CleanCode #WebDevelopment #SoftwareEngineering
To view or add a comment, sign in
-
-
🚨 Is .then().catch() dead after try...catch in JavaScript? Short answer: No. Both are alive and useful. The real difference is how you structure asynchronous code. 🔹 1️⃣ Promise style — .then().catch() This was the original way to handle async operations with Promises. Example: fetch("/api/data") .then(res => res.json()) .then(data => console.log(data)) .catch(err => console.error(err)); ✅ Best when: You want simple promise chains Writing functional pipelines Handling single async operations 🔹 2️⃣ Async/Await style — try...catch Modern JavaScript introduced async/await, making async code look like synchronous code. Example: async function getData() { try { const res = await fetch("/api/data"); const data = await res.json(); console.log(data); } catch (err) { console.error(err); } } ✅ Best when: You have multiple sequential async calls You want cleaner, readable code Handling complex error flows 💡 Key Insight async/await is actually built on top of Promises. So .then() and .catch() are still working under the hood. 👉 It's not about which one is better. 👉 It's about which one fits the situation. 📌 Quick Rule Small async chain → .then().catch() Complex async logic → async/await + try...catch JavaScript keeps evolving, but understanding both patterns makes you a stronger developer. #javascript #webdevelopment #frontend #nodejs #asyncawait #promises #coding #softwaredevelopment #100DaysOfCode
To view or add a comment, sign in
-
-
Solid.js Best Practices A comprehensive guide to best practices for using Solid.js, focusing on common pitfalls and optimal approaches to leverage the framework's reactivity model effectively. - Pass signal functions to JSX props instead of values to maintain reactivity. - Avoid destructuring props; use direct access or `splitProps` to preserve reactivity. - Use function wrappers and `createEffect` for reactive side effects, but prefer `createMemo` for derived values. - Prefer Solid's control-flow components (`<Show>`, `<For>`) over JavaScript conditionals and array methods in JSX. - Use `createResource` or `createAsync` for fetching data instead of `createEffect` to handle loading, errors, and race conditions. - Derive values declaratively rather than syncing state manually with `createEffect`. - Use stores for complex or nested objects to achieve fine-grained reactivity and better performance. - In SolidStart, avoid awaiting in preload functions and use queries and actions for data fetching and mutation. - Emphasize working with Solid's reactivity model to minimize manual synchronization and optimize performance. The guide stresses aligning with Solid.js's reactive principles to build efficient, maintainable applications. https://lnkd.in/gTyA3qqy #solidjs #solid #bestpractices #javascript #typescript #frontend
To view or add a comment, sign in
-
Async/Await vs Promises in JavaScript Handling asynchronous code is a core skill for every frontend developer. Two common approaches: • Promises • Async/Await Both solve the same problem — but the way we write code is different. 🟢 Using Promises function getUser(){ return fetch('/api/user') .then(res => res.json()) .then(data => console.log(data)) .catch(err => console.error(err)); } Works fine… But chaining .then() can become messy in large applications. 🔵 Using Async/Await async function getUser(){ try{ const res = await fetch('/api/user'); const data = await res.json(); console.log(data); }catch(err){ console.error(err); } } • Cleaner. • More readable. • Looks like synchronous code. ⚡ Key Differences ✔ Promises Good for chaining operations. ✔ Async/Await Better readability and easier error handling. 💡 Best Practice Async/Await is built on top of Promises. So understanding Promises first is essential. Good developers know Async/Await. Great developers understand how Promises work underneath. Which one do you prefer in your projects? 👇 #JavaScript #Angular #Frontend #WebDevelopment #AsyncAwait #Programming
To view or add a comment, sign in
-
-
Favorite Project Starter and Tooling for Frontend Efficiency ⚡ Over the past few years, I’ve refined a personal stack that optimizes for type safety, scalability, and developer efficiency. These are the tools I reach for when starting serious frontend and full-stack projects: Framework: React.js Still the most flexible UI library. The ecosystem maturity and composability make it hard to beat. Router: TanStack Router Been using it for ~2 years, and it’s been rock solid. Why I prefer it: • First-class type safety for routes • File-based + code-based routing flexibility • Excellent DX and scalability model Styling: Chakra UI v2 I’ve used Tailwind, ShadCN, Ant Design, Bootstrap, and Chakra UI — but Chakra UI v2 remains my favorite. It strikes the right balance between: • Developer speed • Composability • Clean component architecture Dev Server / Bundler: Vite Fast, minimal config, and no webpack or babel overhead. It removes friction so you can focus on building. Schema Validation: Zod (or Yup) Runtime validation + type safety is essential, especially at API boundaries. Forms: Formik & React Hook Form Both are excellent, but I personally enjoy Formik’s component-based architecture. I liked the pattern so much that I built custom React Hook Form abstractions inspired by Formik’s declarative style. Data Fetching: TanStack Query (React Query) This is non-negotiable for serious apps. • Built-in caching • Cache invalidation • Server state synchronization • Eliminates most global state needs Redux Toolkit Thunk works, but the boilerplate and lack of native caching make it less efficient for modern apps. Full-stack additions: Framework: Next.js Despite frequent patches, it’s still the most production-proven full-stack React framework. Also keeping an eye on TanStack Start. Database: PostgreSQL Reliable, scalable, and production-tested. ORM: Prisma Clean, type-safe, functional query style. Excellent developer experience. Auth: Clerk or Kinde Both provide modern authentication flows with minimal setup. The biggest productivity gains don’t come from knowing more tools — they come from choosing the right ones and using them consistently. Curious — what’s your current go-to starter stack? #ReactJS #FrontendDevelopment #WebDevelopment #SoftwareEngineering #JavaScript #NextJS #TypeScript #DeveloperTools #FrontendEngineering #Programming
To view or add a comment, sign in
-
-
React patterns that often cause subtle bugs Some React code looks completely fine at first glance. But over time, certain patterns can cause confusing bugs or make the UI harder to reason about. Here are a few I try to watch out for 👇 1️⃣ Copying props into state const [user, setUser] = useState(props.user) This creates two sources of truth. If the parent updates props.user, the state inside the component may not update the way you expect. That’s how UI gets out of sync. 2️⃣ Storing values that can be derived Instead of storing: const [fullName, setFullName] = useState("") Sometimes you can simply calculate: const fullName = `${firstName} ${lastName}` Derived state often adds extra logic and unnecessary re-renders. 3️⃣ Lifting state higher than necessary Lifting state up is helpful when multiple components need the same data. But lifting it too high can lead to: • unnecessary re-renders • harder state management • tightly coupled components Sometimes the better answer is to keep state closer to where it is used. 4️⃣ Large components that do too many things When one component handles too much, it becomes harder to: • understand • test • debug Smaller, focused components are usually easier to work with. 5️⃣ Overusing useEffect A lot of logic ends up in useEffect when it does not need to be there. If something can be calculated directly from props or state, it often does not need an effect. None of these patterns are always wrong. But I’ve noticed many React bugs come from state being: • duplicated • misplaced • harder to reason about Keeping one clear source of truth usually makes the UI much easier to understand. What React pattern do you see most often that leads to bugs? #reactjs #frontend #javascript #webdevelopment #softwareengineering #reactdeveloper #reacthooks #frontendengineering
To view or add a comment, sign in
-
-
🚀 Class Component vs Functional Component in React – What’s the Real Difference? When I started learning React, Class Components were everywhere. Today, Functional Components dominate most modern React codebases. Let’s break down the key differences 👇 ⸻ 🔹 1️⃣ Syntax & Structure Class Component • Uses ES6 class • Extends React.Component • Requires render() method Functional Component • Just a JavaScript function • Returns JSX directly • Cleaner and more readable ⸻ 🔹 2️⃣ State Management Class Component • Uses this.state • Updates with this.setState() Functional Component • Uses React Hooks like useState() • Simpler and more intuitive ⸻ 🔹 3️⃣ Lifecycle Methods Class Component • componentDidMount • componentDidUpdate • componentWillUnmount Functional Component • Uses useEffect() hook • Handles all lifecycle logic in one place ⸻ 🔹 4️⃣ Performance & Modern Best Practice • Functional Components + Hooks reduce boilerplate • Easier to test and reuse logic with custom hooks • Preferred in modern React development ⸻ 📌 My Observation: In most new projects, Functional Components are widely used. Class Components are mainly found in legacy applications. ⸻ 💬 Now I’m curious… 👉 Which one are you using in your current project? 👉 Are you still maintaining Class Components or fully moved to Functional Components? Let’s discuss in the comments 👇 #ReactJS #React #FrontendDevelopment #JavaScript #WebDevelopment #SoftwareEngineering #Frontend #Angular #Programming #WebDesign #ReactDeveloper #DeveloperCommunity
To view or add a comment, sign in
-
-
React Hooks provide a way for functional components to use state and lifecycle features without needing class components. Hooks like useState allow components to store and update state, while useEffect handles side effects such as data fetching, subscriptions, or updating the DOM after rendering. Instead of splitting logic across lifecycle methods like componentDidMount or componentDidUpdate, hooks let developers organize related logic together in a simpler and more readable way. This approach reduces complexity and makes React components easier to maintain and test. Another key advantage of React Hooks is that they promote reusable logic through custom hooks. Developers can extract common behaviors—such as API calls, form handling, or authentication logic—into reusable hooks and share them across multiple components. Hooks also work seamlessly with React’s component-based architecture, allowing developers to build dynamic and responsive interfaces while keeping the code clean and modular. By simplifying state management and component behavior, React Hooks have become an essential part of modern React development. #ReactHooks #ReactJS #FrontendDevelopment #JavaScript #WebDevelopment #FullStackDeveloper #SoftwareEngineering
To view or add a comment, sign in
-
-
🎯 Sick of JavaScript framework fatigue? Here’s a breath of fresh air — meet Oat. In a world overloaded with massive UI libraries, tangled dependency trees, and constant churn in the Node.js ecosystem, Oat is a reminder that simplicity still matters. Built by Kailash Nadh, CTO at Zerodha (and seasoned open‑source developer), Oat is an ultra-lightweight UI library designed out of pure frustration with complexity... especially the bloat and dependency-hell of mainstream JS tools. 🔥 What makes Oat stand out? • Just ~8 KB total (≈6 KB CSS + ~2.2 KB JavaScript, gzipped)...tiny and fast to load. • Zero dependencies — no frameworks, no build tools, no package managers. • Semantic HTML-first — native elements are styled without cluttering your markup with classes. • Accessible by default — built with proper ARIA roles and keyboard support baked in. • Easy to theme — customize with CSS variables and even dark mode out of the box. • A library you just include and start building — no tooling or framework lock-in required. The creator openly talks about building this after “unending frustration” with over-engineered solutions and what he calls “Node.js ecosystem trauma” — and honestly, there’s something compelling about that perspective. In the chaos of AI hype and ever-changing web stacks, finding a simple, effective solution feels oddly refreshing — like rediscovering craftsmanship in code. 👉 Is this the future of web development? Or are we just romanticizing the past? Either way, a UI library that prioritizes minimalism, performance, and longevity feels like a much-needed alternative in 2026. https://oat.ink/ #WebDevelopment #JavaScript #UIDesign #DeveloperTools #OpenSource #NotSoAI
To view or add a comment, sign in
-
🚀 never vs void in TypeScript — Know the Difference Many developers confuse `never` and `void` — but they mean very different things. Let’s break it down clearly 👇 🔹 void → “This function returns nothing” Use `void` when a function finishes execution but doesn’t return a value. Example: function logMessage(): void { console.log("Hello TypeScript"); } ✔ The function runs ✔ It completes ✔ It just doesn’t return anything Think of void as: "The function completes, but there’s no return value." -------------------------------------------------- 🔥 never → “This function never finishes” Use `never` when a function never reaches the end. This happens when it: • Throws an error • Has an infinite loop • Terminates execution Example 1: function throwError(message: string): never { throw new Error(message); } Example 2: function infiniteLoop(): never { while (true) {} } ❌ The function never completes ❌ It never returns ❌ Execution stops Think of never as: "This code path is impossible to complete." -------------------------------------------------- ⚖️ Quick Comparison void: - Function finishes execution ✅ - Returns nothing ✅ never: - Function never finishes ❌ - Used for error-throwing functions ✅ - Used for exhaustive type checking ✅ -------------------------------------------------- 🧠 Simple Mental Model void → Returns nothing never → Never returns #TypeScript #JavaScript #WebDevelopment #Programming #SoftwareEngineering create image
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