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

[codemod] react/19/replace-default-props #1400

Closed
quarhodron opened this issue Dec 2, 2024 · 4 comments
Closed

[codemod] react/19/replace-default-props #1400

quarhodron opened this issue Dec 2, 2024 · 4 comments
Labels
bug Something isn't working codemod-issue Any issues related to a codemod, FP or FN. intern

Comments

@quarhodron
Copy link

I already reported the issue but maybe not in the place where you typically look - reactjs/react-codemod#321. There are also other people experiencing the same problem. The gist is when I am running npx codemod react/19/replace-default-props it only removes defaultProps and not adding default props to destructured component props. It happens to all files.
Codemod version: 0.14.2
React/19/replace-default-props: 1.0.0

Faulty codemod

  1. codemod name, e.g., react/19/replace-default-props
  2. source

Sample code snippets

Original

const Button = ({ size, color }) => {
    return <button style={{ color, fontSize: size }}>Click me</button>;
}

Button.defaultProps = {
    size: '16px',
    color: 'blue'
}

Expected

const Button = ({ size = '16px', color = 'blue' }) => {
    return <button style={{ color, fontSize: size }}>Click me</button>;
}

Actual

const Button = ({ size, color }) => {
    return <button style={{ color, fontSize: size }}>Click me</button>;
}

Logs:

Sorry somehow but I cannot get the logs.

I run

codemod react/19/replace-default-props --logs
codemod --log

and logs are empty

Additional context

Add any other context about the problem here. This might include the target project, an explanation of the faulty output related to business logic, relevant links, etc.

@quarhodron quarhodron added codemod-issue Any issues related to a codemod, FP or FN. studio labels Dec 2, 2024
@mohab-sameh mohab-sameh added bug Something isn't working and removed studio labels Dec 3, 2024
@alexbit-codemod
Copy link
Contributor

thanks so much for reporting this issue. we will look into this.

@aweibell
Copy link

I experience the same issue. Properties are removed from Component.defaultProps, but not inserted as default values for props in functional component signature.

@alexbit-codemod
Copy link
Contributor

Thanks for reporting this issue. We’re aware of it and appreciate your feedback. Due to other priorities, it might take some time before we can address it. We’ll keep this issue open and on our radar in the meantime.

@alexbit-codemod
Copy link
Contributor

actually i went ahead and published a new version of this codemod to the registry and tested on the test fixtures that @quarhodron shared and it works fine now... thanks @amirabbas-gh for the fix. closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working codemod-issue Any issues related to a codemod, FP or FN. intern
Projects
None yet
Development

No branches or pull requests

4 participants