Real talk — useEffect almost broke my brain today. 😅 My React journey continues, and I came across one of the trickiest hooks so far. useEffect. At first I felt completely lost. The Codecademy lesson talked about cleanup functions, dependency arrays, side effects — and honestly? My head was spinning. But after stepping back and breaking it down in simpler terms, here's what finally made sense to me: useEffect lets you run code at SPECIFIC MOMENTS in your component's life. Three moments to remember: ```jsx // 1. Run AFTER EVERY render useEffect(() => { }); // 2. Run ONLY ONCE when the page loads useEffect(() => { }, []); // 3. Run WHEN a specific value changes useEffect(() => { }, [forecastType]); ``` The array at the end is called the dependency array — and it controls WHEN the code runs. The analogy that helped me? Think of it like a home security camera 📹 - No array — records 24/7 - Empty array — only records on day one - With a value — only records when that thing changes It's still not 100% clear to me yet — and that's okay. Some concepts take time to really click. 🙏 The lesson today wasn't just about useEffect though — it was about being honest with myself when something is hard, taking a break, and coming back to it instead of forcing it. Still learning, still building, still showing up every day. 💪 Is there a React concept that confused you when you first learned it? Drop it below 👇 #React #JavaScript #useEffect #Frontend #LearningInPublic #100DaysOfCode #SelfTaught
James Eboka’s Post
More Relevant Posts
-
React journey continues — and today's lesson was all about Components. 🧱 A few days ago I talked about JSX. Then the DOM and Virtual DOM. Today? Components made my brain light up in the best way. Here's what I learned: A component is just a JavaScript function that returns JSX. That's it. ```jsx function AnimalFacts() { return <p>Fun fact about animals!</p>; } ``` But what surprised me the most? You can use it like an HTML tag: ```jsx <AnimalFacts /> ``` That one line renders your entire component. Mind = blown. 🤯 The analogy that made it all click for me? LEGO bricks 🧱 Each component is its own brick — built separately, snapped together to make something bigger. And the best part? They're REUSABLE. One component can work for a dolphin, a lobster, and a starfish! Self taught, learning in public, and taking it one concept at a time. 💪 If you're on a similar journey, let's connect! And if you're experienced — what's YOUR favourite analogy for explaining components? Drop it below 👇 #React #JavaScript #Frontend #Components #LearningInPublic #100DaysOfCode #SelfTaught
To view or add a comment, sign in
-
-
Most React devs use hooks daily… But a lot of us are using them wrong (or at least inefficiently). Here are 5 React Hooks you're probably misusing 👇 1. useEffect: Doing too much If your useEffect looks like a mini backend service… that’s a red flag. 👉 Keep it focused: one responsibility per effect. 👉 Avoid unnecessary dependencies (or missing ones 😬). 2. useState: Over-fragmenting state Multiple useState calls for tightly related data = messy logic. 👉 Consider grouping related state into one object 👉 Or use useReducer for complex flows 3. useMemo: Premature optimization Not everything needs memoization. 👉 If your calculation is cheap, skip it 👉 Overusing useMemo can hurt readability more than it helps performance 4. useCallback: Blind usage Wrapping every function in useCallback ≠ optimization 👉 Only use it when passing functions to memoized components 👉 Otherwise, you're just adding complexity 5. useRef: Misunderstood power It’s not just for DOM access 👉 Great for persisting values without re-renders 👉 Perfect for timers, previous values, or mutable variables 💡 Rule of thumb: If you can’t clearly explain why you're using a hook… you probably don’t need it. What’s a hook mistake you’ve made (or still make)? 😄 #React #WebDevelopment #Frontend #JavaScript #Programming #CodingTips
To view or add a comment, sign in
-
-
setTimeout(fn, 0) looks simple. Until a Promise shows up… and breaks your expectations. You write this: setTimeout(() => console.log("timeout"), 0); Promise.resolve().then(() => console.log("promise")); And you think: “Timeout has 0 delay… it should run first.” But the output is: ->promise ->timeout So what’s actually happening? Not magic. Not randomness. Just how JavaScript is designed. When your code runs, this is the order: Run all synchronous code Execute all Promises (microtasks) Then execute setTimeout (macrotasks) Now read that again. 👉 Promises are not faster 👉 They are just scheduled differently Here’s the hidden detail most devs miss: Even if your setTimeout is ready… JavaScript will pause it until every single Promise is finished. So in reality: setTimeout(fn, 0) → “Run me later” Promise.then() → “Run me right after this code” That’s why Promises always win. Not because they’re special… But because the event loop always clears microtasks first. The simple mental model: 👉 sync → promises → timers Once you understand this, you stop guessing async behavior… …and start predicting it. #javascript #webdev #eventloop #programming #promises #settimeout #nodejs #javascript #nestjs #backend #softwareengineering
To view or add a comment, sign in
-
-
💻 5 React mistakes I stopped making (and it improved my code a lot) When I started with React, I used to write code that worked… But not code that was clean, scalable, and maintainable. Here are 5 mistakes I fixed: ❌ 1. Writing everything in one component 👉 Now I break UI into small reusable components ❌ 2. Ignoring proper state management 👉 Learned when to use useState vs useEffect vs lifting state ❌ 3. Not handling performance 👉 Started using memoization (useMemo, useCallback) ❌ 4. Poor folder structure 👉 Now I follow a clean project structure ❌ 5. Debugging randomly 👉 Now I debug step-by-step with proper logs Small changes… but huge difference in code quality 🚀 Still learning every day 👨💻 Which mistake did you make the most? 😅 #ReactJS #FrontendDevelopment #JavaScript #CleanCode #WebDevelopment #SoftwareEngineer
To view or add a comment, sign in
-
Your useEffect is firing 6 times. It's probably not what's in the dependency array. I had [options] in mine. One dependency. Looked fine. The effect ran on every single render anyway — hammering my API with duplicate calls I couldn't explain. The problem wasn't the value. It was the reference. options was an object getting recreated fresh on every render, so React saw a "new" dependency every time — even when the actual data hadn't changed. React doesn't deep-compare objects in the dep array. It checks identity. Fix was wrapping options in useMemo. Two lines. Effect ran once. Done. But honestly, the bigger shift was realising I'd been thinking about dependencies wrong. It's not just what is in the array — it's whether the things in the array are actually stable between renders. If your effect fires more than it should, check the stability of your deps, not just the list. What kills you about useEffect? Curious if this one's common. #react #javascript #reacthooks #frontenddevelopment #webdev
To view or add a comment, sign in
-
-
React Learning Series | Contd... #Day22: Difference between useEffect and useLayoutEffect Most developers use useEffect everywhere ⚛️ But very few truly understand when to use useLayoutEffect 🤔 Here’s the difference in one line 👇 🟢 useEffect → runs AFTER the UI is painted 🟠 useLayoutEffect → runs BEFORE the UI is painted This small timing difference can cause real UI issues 💥 Example: If you measure DOM size using useEffect, users may see a flicker 😬 Switching to useLayoutEffect fixes it instantly ⚡ Rule I follow 👇 ✅ 90% of cases → useEffect ⚠️ Use useLayoutEffect only when layout must be calculated before paint 🚨 Overusing useLayoutEffect can hurt performance since it blocks rendering React is not just about writing components… It’s about understanding when things happen ⏱️ Have you ever faced a UI flicker issue like this? #React #Frontend #JavaScript #WebPerformance
To view or add a comment, sign in
-
This week I didn't just learn React. I made it prove itself to me. Every hook. Every concept. One mini project at a time. 🔥 Here's how it went: useState → built a Counter (okay why do I even need this... oh. OH. the page re-renders. got it.) useEffect → built a Background Color Changer (so this runs AFTER render... and I control when... nice) useCallback → built a Password Generator (wait so without this it was recreating the function every render? that's wild) useRef → built a Stopwatch (persists between renders but doesn't cause one. the quiet one of the family) Custom Hooks → built a Github Profile Generator (this is just... extracting logic into a function? and it works? okay React you're cool) useContext → no more prop drilling. finally. State Lifting → data flows up before it flows down. the mindset shift. Routing → multiple routes, dynamic routes, nested routes. React Router clicked. This is what the learn-and-build strategy actually feels like. You don't understand a hook by reading about it. You understand it when your mini project breaks without it. That's when it stops being syntax and starts being instinct. Next week — Redux Toolkit and starting with backend. The stack is coming together. One week at a time. 🚀 What did YOU build when you first learned React? Drop it below 👇 #ReactJS #WebDevelopment #JavaScript #LearnInPublic #FrontendDevelopment #100DaysOfCode #BuildInPublic #TechJourney #Redux
To view or add a comment, sign in
-
-
😵💫 “Why is my setTimeout running AFTER my Promise?” This question confused me for a long time while working with JavaScript. I thought: 👉 setTimeout(0) = runs immediately 👉 Promise = async → should run later But I was WRONG. I tested this 👇 console.log("Start"); setTimeout(() => console.log("Timeout"), 0); Promise.resolve().then(() => console.log("Promise")); console.log("End"); 👉 Output shocked me: Start → End → Promise → Timeout Then I saw this diagram 👇 …and everything clicked. 💡 The truth: JavaScript doesn’t just run “async code” randomly. It follows a strict priority system: ⚡ Microtasks (Promises) → HIGH priority ⏳ Macrotasks (setTimeout) → LOW priority 🔄 What actually happens: Run all sync code → Start, End Clear Microtask Queue → Promise Then Macrotask Queue → Timeout 🔥 The moment I understood this: Debugging async code became 10x easier No more guessing execution order My React apps felt more predictable 📌 One line to remember: 👉 “Promises beat setTimeout. Always.” If you’re learning frontend, this is one concept you can’t ignore. What was your “wait… what?!” moment in JavaScript? 👇 #JavaScript #FrontendDevelopment #Coding #WebDevelopment #LearnInPublic
To view or add a comment, sign in
-
-
Mastering React State with Hooks Ever felt like your React components are getting cluttered with too much state logic? Here’s a simple idea that can seriously clean things up: Custom Hooks What’s the big deal? Custom hooks let you extract and reuse stateful logic across components. Instead of repeating the same `useState` and `useEffect` logic everywhere, you write it once—and reuse it. Can they really halve your code? In many cases… YES. Imagine this: Instead of writing the same logic in 5 components, you move it into a custom hook like `useFetchData()` or `useFormHandler()`. Now you: Reduce duplication Make components cleaner Improve readability Make debugging easier Simple Example Before: Each component handles its own API call logic After: One custom hook handles everything Components just use it Why you should start using them Keeps your code DRY (Don’t Repeat Yourself) Makes scaling your app easier Encourages better structure Pro Tip Start small. Pick one repeated logic (like form handling or API calls) and convert it into a custom hook. #React #WebDevelopment #Frontend #JavaScript #Coding #SoftwareDevelopment
To view or add a comment, sign in
-
Most React tutorials show basic folder structures—but real-world projects need something more scalable. Here’s the approach I follow to keep my projects clean and production-ready: 🔹 I separate logic by features, not just files 🔹 Keep components reusable and independent 🔹 Move all API logic into services (no messy calls inside components) 🔹 Use custom hooks to simplify complex logic 🔹 Maintain global state with Context or Redux only when needed 🔹 Keep utilities and helpers isolated for better reuse 💡 The goal is simple: Write code today that’s easy to scale tomorrow. As projects grow, structure becomes more important than syntax. What’s your approach—feature-based or file-based structure? 👇 Follow me - Abhishek Anand 😍 #share #like #repost #ReactJS #FrontendDevelopment #MERNStack #CleanCode #WebDevelopment #Javascript Credit #jamesCodeLab
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
Great 👏, keep going brother ✨