Top 6 React Hook Mistakes Beginners Make

Web Dev Simplified · 614K views · 2022 · 21:18

Open on YouTube

Web developmenttutorial

Why Stack Overflow recommends it

Stack Overflow users link it in comments when explaining useState and hook-dependency gotchas, such as why a state value does not update as expected.

Recommended by 2 people across 2 different months, 2023 to 2023.

What it is

A 21-minute tutorial from Web Dev Simplified that walks through six common React hook mistakes beginners make. Topics include unneeded state, the function form of useState, async state updates, unnecessary useEffects, referential equality problems, and not aborting fetch requests.

What people said

Recommends luicfrr · 2023-03 · Stack Overflow · on “Why does the function provided by Context.Provider not change the value from the same context?”

Also try using arrow function when setting your variables with useState. E.g.: `setAuth(() => 'somevalue')` this will make sure your value always changes to the latest setted value, for a better explanation see this [this video]

Recommends samthecodingman · 2023-12 · Stack Overflow · on “Why is my 'postInfo' state variable null when calling a function, despite being updated correctly in React Native and Firebase?”

@naechebango I've got into the habit of associating the thought "but it didn't update" with "check hook dependencies". I find that programming YouTubers are a pretty good source of keeping up to date with common gotchas, just ignore the video titles. Pulling from my watch history, watch this video [this video] , this video [LINK] , and this video [LINK] . This should seed your algorithm to suggest similar content.

Cites Matvey Sokolovsky · 2023-04 · Stack Overflow · on “What is BETTER useState or useRef, when handling multiple form inputs in React?”

DISCLAIMER : i'm new at React, and just trying to build good habits. So, the example would be a simple contacts app, where you type in names, and all the names are rendered below the input field. pic.1 simple contacts app mechanics [LINK] First, and the most intuitive way, of making this work is using useState() hook with our input field. It's also widely suggested in tutorials around the web. method 1 with useState() : const [inputState, setInputState] = useState(''); const [people, setPeople] = useState([]); const onChange = (event) => { setInputState(event.target.value) } const onSubmit = (e) => { e.preventDefault() setPeople([...people, inputState]) setInputState('') // pay extra attenti