Skip to content

Warning : "defaultProps" will be removed #7287

@khuyenho

Description

@khuyenho

Describe the problem

React version 18 doesn't use defaultProps anymore. It gave this warning every time I ran the app, and the logs are very long, it kind of annoying.
image

The root of the problem here: https://github.com/elastic/eui/blob/main/src/components/button/button.tsx#L135
Other components might also be affected.

Proposed solution

Before

EuiButton.defaultProps = {
  size: 'm',
  color: 'primary',
};

After

export const EuiButton = ({ size = 'm', color = 'primary' }) => {
  // Your component logic here
  return (
    <EuiButton size={size} color={color}>
      Button
    </EuiButton>
  );
};

You can set default values directly within the component function.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions