Skip to content

What Typescript type to require for useRef in AsyncSelect #4669

Answered by Methuselah96
jjmwhite asked this question in Q&A
Discussion options

You must be logged in to vote

Typing it this way works for me:

import { useRef } from "react";
import AsyncSelect from "react-select/async";

interface Option {}

export default function App() {
  const asyncRef = useRef<AsyncSelect<Option> | null>(null);

  return (
    <>
      <AsyncSelect<Option> ref={asyncRef} />
      <button
        onClick={() => {
          if (asyncRef.current) {
            asyncRef.current.focus();
          }
        }}
      >
        Focus
      </button>
    </>
  );
}

CodeSandbox

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@Joe312341
Comment options

@Methuselah96
Comment options

@sim51
Comment options

@Methuselah96
Comment options

@PranuPranav97
Comment options

Answer selected by jjmwhite
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants