Skip to content

Warning : "defaultProps" will be removed #7287

Closed

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.

Activity

  1. JasonStoltz commented on Oct 16, 2023

    @JasonStoltz
    Contributor

    Hey team 👋 . I marked this as high priority and sized it as small. Let's see if we can get this cleaned up quickly.

  2. self-assigned this
    on Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions