Mastering useEffect: Beware of depending on values you set

preview_player
Показать описание
We start taming React's useEffect by laying down some rules because misusing useEffect can cause serious issues with React applications on NextJS, Vite, or Create React App. Rule number one is to avoid depending on values we set.

#shorts #react #useeffect #nextjs #nextjs13
Рекомендации по теме
Комментарии
Автор

"beware of depending on values that you set" also sounds like some eastern philosophy

Yusuf-okrk
Автор

setInterval and setTimeout on React have been always messy to implement. Every time I need to work with those methods, I need to be very careful because it's not intuitive for remembering. I don't like React mental model cause of that, so for personal projects I'm moving to SolidJS, where timer methods become intuitive again.

webblocksapp
Автор

Once spent like 5 hours trying to find a way to solve EXACTLY this problem until i finally poured through the docs to find the functional setState method.

owenjones
Автор

Should be spending more time in the docs. I wasted lots of time by using direct update and not utilizing the clean-up functions. Thanks so much for this.

aydzz
Автор

I did not quite understand what the return function of a `useEffect` hook was supposed to do. Now I do, and I have always needed it without even knowing. 😀😆

Thank you.

cyonii
Автор

just pasted a screenshot of the initial code into chatgpt and it suggested the correct revised code!

wealthassistant
Автор

What is meant here by a "stale closure"?

ttncmok
Автор

What's the theme and style of your vscode!

surajpokhrel
Автор

Shouldn’t count be set as a dependency?

noy
Автор

This is great. Is there a way to save these shorts for quick reference?

nitinupadhyay
Автор

The cleanup function doesn't cause any re-render, which means the component will no longer update any state. So How does the callback function runs again even we didn't watch for any changes?

dotacontent