OpenHands icon indicating copy to clipboard operation
OpenHands copied to clipboard

Replace the usage of `defaultProps` for React components with JavaScript default parameters.

Open amanape opened this issue 1 year ago • 0 comments

Since React 18.3.0, a console warning displays for any usage of .defaultProps. It is now deprecated.

Warning:

Warning: <COMPONENT>: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead.

As the in the README link shared above, we should make these changes:

BEFORE:

interface ComponentProps = {
  optionalProp?: false;
}

const Component: React.FC<ComponentProps> = ({ optionalProp }) => /* ... */;

Component.defaultProps = {
  optionalProp = false;
};

AFTER:

interface ComponentProps = {
  optionalProp?: false;
}

const Component: React.FC<ComponentProps> = ({ optionalProp = false }) => /* ... */;

Additionally, we have to disable the react/require-default-props rule from ESLint since it encourages the use of this now deprecated method (we should probably update it to the latest major release)

amanape avatar May 24 '24 06:05 amanape