Mastering useEffects: Avoid Functions as Dependencies

preview_player
Показать описание
It's hard to make a custom hook that works well with functions because functions usually change with every render (unless you use useCallback). Find out a way to make custom hooks with functions easier by using useRef. This will definitely help you in your React 18, NextJS, Create React App, and Remix applications.

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

the most unrated programmer on youtube, he deserves more attention, thank you good man

djkepa
Автор

Omg! So that was the problem I've been having. I'm so enlightened right now! Thank you so so much for this video.

yusufaltundal
Автор

Thanks a lot for making all the content in your channel!

ludanin
Автор

Thanks for these videos, man! I'm learning a lot of new things...

mohitgangrade
Автор

Nice video, but noticed a small bug. The ref is called success on line 3 and then successRef on line 4. Otherwise, thank you for the content.

hitarthdesai
Автор

Wouldn't it be better if the dependency array contained only the options object? With the options object being memoized of course.

yazoouf
Автор

Would the ref approach work reliably with react 18's async rendering? Pretty cool technique to make more ergonomic hooks.

lambda_tubes
Автор

yeah this is why I haven't switched from vue. but I need to since vue has no native version

glowiever
Автор

Hi Jack.. One Question. Where came from the variable "successRef" ??

robertogermanpuentesdiaz
Автор

Hey sir,
An out-of-topic question - What is the font you are using for your code snippets?

DarkOceanShark
Автор

You were using "options?.onSuccess". Is "options" optional? If it is then shouldn't the "url" also be accessed in that manner? However, correct me if I'm wrong, we can't use optional values in the deps array in the first place so, options must always be defined. So both url and onSuccess would have to be accessed like this - "options.url, options.onSuccess"

geralt
Автор

Is it just me or is there getting to be too many footguns in useEffect?? Like in some ways it seemed a lot simpler with good ol' componentDidMount.

lingdocs
Автор

Why we can't put the useCallback inside useFetch Hook? That would be bad?

ricardoolartepuell
Автор

I am kinda confused, from the success and successRef
What is successRef?
Is it supposed to be success.current? If it is like that, wouldn't that throw an error reinitialising a Constant?

I know the solution of the useCallback and i understand the overall of the concept but the useRef i only used it with inputs and didn't know i can use it passed props

muhammedibrahem
Автор

I have a question, why we need to declare onSuccess as a dependency? No meaning at all, or do I missing something?

PROTOTURKCOM
Автор

Could you remake this with easy to read example

morningtarr
Автор

This isn’t the most ergonomic part of react

asdqwe
Автор

This is why react hooks are a horrible mess

LarsRyeJeppesen
Автор

Could you expand on why useFetch is getting a new ref?

caizza