DEV Community

Gabriel Linassi
Gabriel Linassi

Posted on

Quick Javascript tip

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

Discussion (0)