TheOdinProject / curriculum

The open curriculum for learning web development
https://www.theodinproject.com/
Other
9.7k stars 13.12k forks source link

How To Deal With Side Effects: Wrong use cases for useEffect #26132

Closed mateusznurzynski closed 1 year ago

mateusznurzynski commented 1 year ago

Describe your suggestion

This article in the assignments section provides wrong information: https://dev.to/colocodes/6-use-cases-of-the-useeffect-reactjs-hook-282o

It uses the useEffect hook for things that don't need it.

For example it uses it for input validation:

    useEffect(() => {
        if (input.length < 5 || /\d/.test(input)) {
            setIsValid(false);
        } else {
            setIsValid(true);
        }
    }, [input]);

The useEffect hook is not necessary here. (You could just use an event handler)

The use cases provided in this article are very confusing, because they contradict with what was said in the "But do we need the effect?" section of the lesson and in the react docs. React docs: https://react.dev/learn/you-might-not-need-an-effect Odin lesson: https://www.theodinproject.com/lessons/node-path-react-new-how-to-deal-with-side-effects#but-do-we-need-the-effect

There are also some other issues that people have pointed out in the comments section of this article.

Path

Node / JS

Lesson Url

https://www.theodinproject.com/lessons/node-path-react-new-how-to-deal-with-side-effects#but-do-we-need-the-effect

Checks

(Optional) Discord Name

raptor_3315

(Optional) Additional Comments

No response

JayRKyd commented 1 year ago

I would like to be assigned to this issue please.

wise-king-sullyman commented 1 year ago

These critiques do seem valid and substantive enough to probably warrant the removal of this article IMO, @TheOdinProject/react any opposition?

ManonLef commented 1 year ago

I agree, this is confusing and should be removed or replaced. If there's an alternative with a good amount of example use cases (and explanations on why they are great candidates for useEffect), that would have my preference since otherwise this lesson and its articles mostly emphasises when NOT to use useEffect.

wise-king-sullyman commented 1 year ago

Since I've had a +1 and no objections I'll go ahead and assign you @JayRKyd. Thanks for volunteering to do this!