Skip to content

FunctionComp.defaultProps is going to be deprecated in React 18.3.0 #7057

@isBatak

Description

@isBatak

Description

This issue is based on this Discord report

The error that happens when using Portal with Next.js 13.0.5

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

The root of the problem:

Portal.defaultProps = {

Links to React PR and ESLint change:
facebook/react#25699
jsx-eslint/eslint-plugin-react#2396

Other components might also be affected.

Problem Statement/Justification

This will make Chakra UI more aligned with React 18.3.0

Proposed Solution or API

Change:

Portal.defaultProps = {
  appendToParentPortal: true,
}

Into:

export function Portal(props: PortalProps) {
  const { containerRef, ...rest } = { appendToParentPortal: true, ...props };
  return containerRef ? (
    <ContainerPortal containerRef={containerRef} {...rest} />
  ) : (
    <DefaultPortal {...rest} />
  )
}

The goal isn't to remove defaultProps, but to change how they're defined on function components.

Alternatives

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions