Theo and Dan Abramov useEffect Interview Question

I know its old but I am reviewing Theo's practice interview with Dan Abramov (https://www.youtube.com/watch?v=uqII0AOW1NM) and had a question about the autoscroll section. Dan says most people would want to do this in an effect (my first instinct), but Dan said he wouldnt want to do this and you're "not supposed to do things that are disruptive there". Can anyone please explain what the reason for this/link the react docs that explain why this is?
Theo - t3․gg
YouTube
Dan Abramov SLAYS Frontend Interview w/ Ex-Twitch Engineer
Hope you React fans are excited for this one! We were so lucky to have Dan Abramov on for a stop during his mock interview loop :) If you don't already follow him, fix that! He's been streaming on Youtube more so be sure to sub there!! Dan's Twitter - https://twitter.com/dan_abramov Dan's Youtube - https://www.youtube.com/c/danabramov8 If you ...
Solution:
In that specific case, using an effect isn't great since the autoscroll should be happening in response to a event coming through, not some state changing - hence it should be done in the handler of the event. There's a lot of cases like that which are documented here: https://react.dev/learn/you-might-not-need-an-effect
You Might Not Need an Effect – React
The library for web and native user interfaces
Jump to solution
2 Replies
Solution
Brendonovich
Brendonovich2y ago
In that specific case, using an effect isn't great since the autoscroll should be happening in response to a event coming through, not some state changing - hence it should be done in the handler of the event. There's a lot of cases like that which are documented here: https://react.dev/learn/you-might-not-need-an-effect
You Might Not Need an Effect – React
The library for web and native user interfaces
tyler4949
tyler4949OP2y ago
Thank you!
Want results from more Discord servers?
Add your server