Skip to content

ref doesn't reference #622

@frederickf

Description

@frederickf

Before you start - checklist

  • I followed instructions in documentation written for my React-Date-Picker version
  • I have checked if this bug is not already reported

Description

I'm in the process of updating to the latest version. We were previously using ^8.1.1. Upon updating to ^10.2.0 ref.current created with useRef() is always null. We were using the ref to focus the date picker when a user clicked the label.

I've created demo using CodeSandbox that reproduces the issue https://codesandbox.io/s/react-date-picker-useref-demo-lmkhjz?file=/src/App.js

You can see in the demo by looking at the console that react is throwing a warning:

Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

Steps to reproduce

  1. Go to https://codesandbox.io/s/react-date-picker-useref-demo-lmkhjz?file=/src/App.js
  2. Open console
  3. See Warning
  4. Click on the label above the date picker
  5. In console see ref.current is null

Expected behavior

ref.current is a reference to a dom node and React doesn't throw warning

Actual behavior

ref.current is null, react throws warning

Additional information

No response

Environment

  • Browser (if applicable): Firefox, Chrome
  • React-Date-Picker version: 10.2.0
  • React version: 18.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    freshquestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions