2

I'm managing my forms using react-hook-form. but I also need to manage an element's click event. In this case, I have to set both refs

   let inputRef = useRef(null);

   const onClick = input => {
      input.click();
   };

<input
     type="file" 
     ref={ref => {
        inputRef = ref;
        register();
     }},
     onClick={() => onClick(inputRef)}
></input>

How can I set multiple refs

pneuma
  • 151
  • 1
  • 9

2 Answers2

1
              inputRef={ref => {
                 inputLogoSquare = ref;
                 register(ref);
              }}

this is the answer

pneuma
  • 151
  • 1
  • 9
0

I think it's the best solution.

const myRef = useRef(null);

<input ref={(ref) => { 
         myRef.current = ref; 
         register(ref); 
       }} />
iranimij
  • 63
  • 9