2

I have a problem defining type in typescript for ref.

I have questionsRef which is a list of refs.

  const questionsRef = useRef<Array<HTMLDivElement | null>>([]);

I want to pass that questionsRef to the utility function, but Typescript requires the correct type of arguments.

How to define questiosnRef: Type here?

const focusNextQuestion = (questionsRef: any, nextQuestion: any) => {
  if (questionsRef.current) {
   // some code
};
0

1 Answer 1

3

Try this:

React.useRef<Array<React.RefObject<HTMLDivElement | null>>>();
Sign up to request clarification or add additional context in comments.

2 Comments

Hey @Ekkoko I need defining someting similar to that inside of utility function: const focusNextQuestion = (questionsRef: HERE NEED TO DEINE SAME REF, nextQuestion: any)
If I understood correctly the type of the questionsRef should be React.RefObject<HTMLDivElement | null>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.