is it anti-pattern to append .current after useRef in react

Viewed 64

I've recently been debugging some old React code developed by my colleagues and noticed that they would declare some useRef's inside their functional components like this:

const refName = useRef(...).current;

This isn't the first time I've seen ref's declared like this in the React community, but it seems to be rare.

I can only assume that they've done this so that they only have to reference it by the variable name further down the line - as opposed to variableName.current.

So, this got me wondering: other than making the code a little bit cleaner, are there any clear downsides or benefits to declaring references this way?

0 Answers
Related