1.0.8 • Published 1 year ago

react-codemod-defaultprops v1.0.8

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

react-codemod-default-props

This is a JSCodeshift React codemod that helps update React defaultProps API to props destructuring with default values to facilitate the upgrade to React 19.

Usage

npx react-codemod-default-props

This will start an interactive wizard, and then run the transform.

Before:
function IconButton(props) {
  const {
    className,
    disabled,
    icon,
    label,
    link,
    onLinkClick,
    stopPropagation,
    withIcon,
    ...rest,
  } = props;

  return <Button>...</Button>;
}

IconButton.defaultProps = {
  disabled: false,
  icon: <Icon />,
  label: '',
  stopPropagation: false,
  withIcon: true,
  id: '',
  name: '',
};

export default memo(IconButton);
After:
function IconButton(props) {
  const {
    className,
    disabled = false,
    icon = <Icon />,
    label = "",
    link,
    onLinkClick,
    stopPropagation = false,
    withIcon = true,
  } = props;

  rest.id ??= "";
  rest.name ??= "";

  return <Button>...</Button>;
}

export default memo(IconButton);
1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago