Skip to content

Commit d982e32

Browse files
Docs(Learn): clarify Challenge 2 explanation about getVisibleTodos()
1 parent 8d1b914 commit d982e32

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/content/learn/you-might-not-need-an-effect.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,9 @@ input { margin-top: 10px; }
12721272
12731273
</Sandpack>
12741274
1275-
This approach satisfies the requirements too. When you type into the input, only the `text` state variable updates. Since the `text` state variable is in the child `NewTodo` component, the parent `TodoList` component won't get re-rendered. This is why `getVisibleTodos()` doesn't get called when you type. (It would still be called if the `TodoList` re-renders for another reason.)
1275+
This approach works because `getVisibleTodos()` is only called when its dependencies (`todos` or `showActive`) change. In the original implementation, typing in the input doesn’t trigger additional calls because the `text` state is local to the `NewTodo` component and not part of the dependencies.
1276+
1277+
The key idea is that both the initial and extracted versions avoid unnecessary recomputations—the update to `text` does not cause `getVisibleTodos()` to run. Extracting `NewTodo` mainly improves clarity by keeping the input state isolated, not by changing performance behavior.
12761278
12771279
</Solution>
12781280

0 commit comments

Comments
 (0)