react-codemod icon indicating copy to clipboard operation
react-codemod copied to clipboard

react/19/replace-default-props does not add ES6 default parameters

Open quarhodron opened this issue 1 year ago • 2 comments

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 avatar Aug 12 '24 10:08 quarhodron