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

React 18 Enhancements: Refactor defaultProps to default function parameters #13424

Closed
76 tasks done
Tracked by #13623
tay1orjones opened this issue Mar 29, 2023 · 2 comments · Fixed by #14720
Closed
76 tasks done
Tracked by #13623

React 18 Enhancements: Refactor defaultProps to default function parameters #13424

tay1orjones opened this issue Mar 29, 2023 · 2 comments · Fixed by #14720
Labels
package: @carbon/react @carbon/react package: icons-react @carbon/icons-react package: pictograms-react @carbon/pictograms-react planning: umbrella Umbrella issues, surfaced in Projects views role: dev 🤖 type: infrastructure 🤖 Issues relating to devops, tech debt, etc.
Milestone

Comments

@tay1orjones
Copy link
Member

tay1orjones commented Mar 29, 2023

React 18.3 will introduce a deprecation of defaultProps. Components will need to move off defaultProps and instead use default function parameters.

Additionally, we'll need to ensure that default values are static #10777 - this mostly includes function props

We probably should wait to tackle this until React 18.3 lands to see if the react team has additional recommendations for this work and/or a codemod available to automate this refactor.

// TODO: provide code example

Components to refactor

@tay1orjones tay1orjones added planning: umbrella Umbrella issues, surfaced in Projects views role: dev 🤖 type: infrastructure 🤖 Issues relating to devops, tech debt, etc. package: icons-react @carbon/icons-react package: pictograms-react @carbon/pictograms-react package: @carbon/react @carbon/react labels Mar 29, 2023
@tay1orjones tay1orjones added this to the 2023 Q2 milestone Mar 29, 2023
@sstrubberg sstrubberg removed this from the 2023 Q2 milestone Mar 29, 2023
@tay1orjones tay1orjones added this to the 2023 Q2 milestone Apr 10, 2023
@sstrubberg sstrubberg changed the title Refactor defaultProps to default function parameters React 18 Migration: Refactor defaultProps to default function parameters Apr 14, 2023
@tay1orjones tay1orjones changed the title React 18 Migration: Refactor defaultProps to default function parameters React 18 Enhancements: Refactor defaultProps to default function parameters Apr 18, 2023
@tay1orjones tay1orjones removed this from the 2023 Q2 milestone Apr 19, 2023
@tay1orjones tay1orjones added this to the 2023 Q4 milestone Jun 7, 2023
@tuccitj
Copy link

tuccitj commented Jul 24, 2023

Current getting this error on UIShell.Content.js. If someone can share a sample of the refactor, I can start banging the rest out.

@tw15egan
Copy link
Member

@tuccitj that would be great if you want to start working on this. One example of a component that has been converted is IconSwitch. These lines specifically. For example, in UIShell/Content you'd remove

Content.defaultProps = {
  tagName: 'main',
};

and instead, make it a default function parameter

const Content = ({
  className: customClassName,
  children,
  tagName = 'main',
  ...rest
}) => {

For functions, you';d do something like this:

const noopFn = () => {};

const Content = ({
    onClick = noopFn,
     ...
}) => {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: @carbon/react @carbon/react package: icons-react @carbon/icons-react package: pictograms-react @carbon/pictograms-react planning: umbrella Umbrella issues, surfaced in Projects views role: dev 🤖 type: infrastructure 🤖 Issues relating to devops, tech debt, etc.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants