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/19/replace-default-props does not add ES6 default parameters #321

Open
quarhodron opened this issue Aug 12, 2024 · 4 comments
Open

Comments

@quarhodron
Copy link

The example nicely shows that default props from defaultProps will be added to the component props as shown in this example https://github.com/codemod-com/codemod/tree/main/packages/codemods/react/19/replace-default-props.

However, when I am running npx codemod react/19/replace-default-props it only removes defaultProps and not adding default props to destructured component props. Even when I tried to just have the exact code from the mentioned example, it only removed this block:

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

and the rest was left untouched

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

I worked on codemod in version 0.13.3.
Tested on project either in pure js or TS with tsx files.
Tested either on Node 18.17.1 or 20.15.1.
Tested on React either 18.3.1 and 18.2.0. Not sure if it matters.
All of them resulted in removing only defaultProps and not adding ES6 default parameters to component.

@quarhodron quarhodron changed the title react/19/replace-default-props does not add default props react/19/replace-default-props does not add ES6 default parameters Aug 12, 2024
@quarhodron
Copy link
Author

@DmytroHryshyn I saw you were contributing the most to the codemod. Can you look into that 🙏 ?

@mohab-sameh
Copy link
Contributor

Thanks for reporting this @quarhodron! @DmytroHryshyn will be away for some time. @arybitskiy can you please take a look at this?

@quarhodron
Copy link
Author

@mohab-sameh do you think @arybitskiy will be able to still look at it because it seems he hasn't done any commits recently

@xander-marjoram
Copy link

xander-marjoram commented Oct 17, 2024

I'm also seeing the same issue.

Initially the codemod was returning "No changes were made during the codemod run.". I think this is because much of our code is in the following format:

const defaultProps = {
    size: '16px',
    color: 'blue',
};

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

Button.defaultProps = defaultProps;

If I manually remove the defaultProps variable to match the example, the Button.defaultProps assignment is simply removed without updating the destructured props.

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

No branches or pull requests

3 participants