Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
isBatak opened this issue Nov 29, 2022 · 2 comments · Fixed by #7068
Closed

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

isBatak opened this issue Nov 29, 2022 · 2 comments · Fixed by #7068

Comments

@isBatak
Copy link
Contributor

isBatak commented Nov 29, 2022

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

@isBatak isBatak added the needs triage Issues and pull requests that need triage attention label Nov 29, 2022
@TimKolberger TimKolberger added PR welcome 😇 and removed needs triage Issues and pull requests that need triage attention labels Nov 30, 2022
@AlexKvazos
Copy link

PR submmited. This is my first contribution, please let know if I missed anything.

@cereallarceny
Copy link
Contributor

I've also submitted a PR which sufficiently solves the problem for all components: #7068

The PR submitted by @AlexKvazos only solved the problem in one component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants