HackIndia Logo
HackathonsNewsSkillsGrowth
HackIndia LogoContact: +91 9910125804

General

  • Companies
  • Colleges
  • Board of Advisors
  • Brand Ambassadors
  • FAQ
  • Contact
  • Report a Bug

Hackathons

  • Upcoming Hackathons
  • Judges
  • Mentors
  • Partners
  • Participating Colleges

Resources

  • About Us
  • Branding
  • Latest News
  • Growth
  • Skills
  • Ecosystem
  • Forum
  • Ideas
  • Prompt Optimizer
  • How to earn XP

© 2026 HackIndia. All rights reserved.

Privacy PolicyTerms of ServiceCode of ConductSitemap

Build 2.139 · 09 Nov 2026, 10:59 UTC

    HackIndia
    HackathonsNewsInternshipsSkillsGrowth
    ReactWorking towardsReact
    0%

    0 of 10 steps done · +100 XP · +50 SHARP when it is yours

    1. 1Start React the current way4 min · +10 XP · +5 SHARP
    2. 2Pass data with props4 min · +10 XP · +5 SHARP
    3. 3Use state without clutter5 min · +10 XP · +5 SHARP
    4. 4Render lists with stable keys5 min · +10 XP · +5 SHARP
    5. 5Build controlled forms4 min · +10 XP · +5 SHARP
    6. 6Lift state between components4 min · +10 XP · +5 SHARP
    7. 7Use effects only when needed4 min · +10 XP · +5 SHARP
    8. 8Ship your React repo5 min · +10 XP · +5 SHARP
    9. The check10 questions, 7 to pass · +10 SHARP
    10. Hand in the taskA project that uses the skill
    11. Skill and certificate+100 XP · +50 SHARP
    Lesson 7 of 8 4 min

    React

    Use effects only when needed

    • +10 XP for this lesson
    • +100 XP when the skill is proved
    • 3 learning it right now
    In 30 seconds
    • Decide when useEffect is actually needed in your React app.
    • Avoid effects for computed values, event work, and shared state fixes.
    Add one justified effect, or write a clear note saying none is needed.
    Key point

    One rule

    Use useEffect only to synchronize your component with something outside React. Examples: browser storage, a timer, a map widget, a chat connection, or a non-React library.

    If you are only calculating a value from props or state, do it during render. If you are responding to a click or form submit, do it in the event handler.

    What counts external

    React already handles rendering from state and props. Your app does not need an effect to keep two React values in sync. That usually creates duplicate state and bugs.

    An external system is something React does not control. localStorage is outside React. document.title is outside React. A server connection is outside React.

    Common mistake

    Common wrong effect

    Beginners often store a filtered list in state, then use an effect to update it when the search text changes. That is not needed.

    The filtered list can be computed from the current list and search text during render. Less state means fewer bugs.

    function ProjectList({ projects, search }) {
      const visibleProjects = projects.filter((project) =>
        project.name.toLowerCase().includes(search.toLowerCase())
      );
    
      return (
        <ul>
          {visibleProjects.map((project) => (
            <li key={project.id}>{project.name}</li>
          ))}
        </ul>
      );
    }
    Example

    Useful effect

    This effect is justified because document.title belongs to the browser, not React. The dependency list includes the value used inside the effect.

    Call Hooks at the top level of your component. Do not put useEffect inside an if block, loop, or nested function.

    import { useEffect, useState } from 'react';
    
    export default function App() {
      const [projects, setProjects] = useState([]);
      const [name, setName] = useState('');
    
      useEffect(() => {
        document.title = `${projects.length} projects saved`;
      }, [projects.length]);
    
      function addProject(event) {
        event.preventDefault();
        const trimmedName = name.trim();
        if (!trimmedName) return;
    
        setProjects([
          ...projects,
          { id: crypto.randomUUID(), name: trimmedName }
        ]);
        setName('');
      }
    
      return (
        <form onSubmit={addProject}>
          <input
            value={name}
            onChange={(event) => setName(event.target.value)}
            placeholder="Project name"
          />
          <button>Add project</button>
        </form>
      );
    }
    Your to-do

    Effect checklist

    Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.

    0 of 5 done

    Tip

    Use AI carefully

    You can ask an AI tool to review your component: “Find useEffect calls that can be removed. Explain why.” Do not accept the answer blindly.

    Check three things yourself: is there an external system, are dependencies complete, and can the value be computed during render instead.

    Your to-do

    Do this now

    Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.

    0 of 5 done

    Sources

    Checked against the current documentation on 21 September 2026.

    • useEffect · react.dev
    • useState · react.dev

    Quick check

    0 of 2 right
    1.Your search result list comes from projects and searchText. What should you usually do?
    2.Which useEffect is justified in this lesson?

    Answer the quick check to finish this lesson.

    ← Lesson 6Skip to lesson 8 →
    React
    Working towards
    React +100 XP

    0 of 8 lessons done · proved by a project that uses the skill

    See the track