trussworks / react-uswds

USWDS 3.0 components built in React
https://trussworks.github.io/react-uswds/
Apache License 2.0
169 stars 78 forks source link

[fix] DatePicker component uses defaultProps which is to be deprecated and causes console warning. #2918

Open Steven7926 opened 1 month ago

Steven7926 commented 1 month ago

ReactUSWDS Version & USWDS Version:

"@trussworks/react-uswds": "^9.0.0",
"@uswds/uswds": "3.7.1",

Describe the bug

When building a form using your component library I kept running into a console waring stating:

"Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead."

Upon further investigation I found that this was coming from the DatePicker component. At the end of DatePicker.tsx you are using DatePicker.defaultProps = { minDate: DEFAULT_MIN_DATE, } to set a minimum allowable date for the datepicker component, this is trggering the warning.
defaultProps is also used in the Tooltip component. To Reproduce Steps to reproduce the behavior:

  1. Create a page and use the datepicker and tooltip components
  2. Render that page
  3. Open dev tools in the browser and view the console
  4. See error: "Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead."

Expected behavior

No warning should appear in the console to prep your library for deprecating feature support.

Screenshots

Additional context

Device and Browser Information (please complete the following information if describing a UI bug): Google Chrome running a Vite React application on Windows.

aligg commented 3 weeks ago

@Steven7926 and @brandonlenz (saw you've reviewed some things recently) - put up a quick PR for this one in case anyone has cycles to review: https://github.com/trussworks/react-uswds/pull/2949

Looks like workflows need approval from a maintainer as well.