Skip to content

ref error with Select component #1537

Answered by SiTaggart
HartiganHM asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks @HartiganHM

For prosperity and pulling out of Slack if someone comes across this again, what you need to do when wrapping one of the Paste components and you need to rely on refs, is forward the ref on your wrapper component and pass it down to the Paste component.

If you don't, the ref to the Paste component is not exposed to consumers of your wrapper component, in this case the CompositeSelect component. That's why React-hook-form can't find the ref.

const CompositeSelect = forwardRef(
  (
    {
      children,
      id,
      label,
      marginBottom,
      onChange,
      required,
      value,
      width,
      ...rest
    }: CompositeSelectProps,
    ref: Ref<HTMLSelectElement

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by HartiganHM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants