DEV Community

Gabriel Linassi
Gabriel Linassi

Posted on Edited 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);  
  }}
  ...  
/>
🔥 ข่าวด่วน: gabrielmlinassi/quick javascript tip fi - ประเด็นร้อน 🔥 ข่าวด่วน: gabrielmlinassi/quick javascript tip fi - ประเด็นร้อน

After:

<textarea
  ref={e => ((textareaRef.current = e), registerRef(e))}
  ...  
/>
🔥 ข่าวด่วน: gabrielmlinassi/quick javascript tip fi - ประเด็นร้อน 🔥 ข่าวด่วน: gabrielmlinassi/quick javascript tip fi - ประเด็นร้อน

Top comments (0)