Quick Javascript tip
Gabriel Linassi

Gabriel Linassi @gabrielmlinassi

About: Front-End Web Dev (React.js)

Location:
Florianópolis - SC / Brazil
Joined:
Jan 4, 2020

Quick Javascript tip

Publish Date: May 20 '22
7 0

While developing a Textarea component in React with React-hook-form,
I needed to add two refs to the textarea field but it was a bit uggly so I tried to make that prettier:

Before:

<textarea
  ref={e => {
    textareaRef.current = e;
    registerRef(e);  
  }}
  ...  
/>
Enter fullscreen mode Exit fullscreen mode

After:

<textarea
  ref={e => ((textareaRef.current = e), registerRef(e))}
  ...  
/>
Enter fullscreen mode Exit fullscreen mode

Comments 0 total

    Add comment