3 Minutes With Kent

Don't set your ref in your component body

Informações:

Sinopse

https://epicreact.dev/the-latest-ref-pattern-in-react Hey your friends. So I get this question of fair amount and so I thought I'd try to answer it and podcast form and the question is why don't why is it not a good idea to set a ref during your render function? So there are exceptions to this and understanding the reasoning will help you understand what those exceptions are. But basically, if you read my blog post on the Epic React dot dev slash articles, there's a blog post about the latest ref pattern and in that I put a use layout effect and,There with ref dot current equals some callback or whatever And a lot of people ask me why do you need to put that in a use effect? Why can't you just put that? You know you're calling it every render anyway so you may as well just put it directly in the render function. So the reason that you don't want to do this is it actually is mostly just for future proofing. So right now that will technically work and it and it there shouldn't be any problem with it, but when e