Skip to content

Commit 1d8befd

Browse files
committed
feat: add react-19-replace-default-props transform
1 parent 7b1901c commit 1d8befd

18 files changed

+517
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const Button = ({ size, color }) => {
2+
return <button style={{ color, fontSize: size }}>Click me</button>;
3+
};
4+
5+
Button.defaultProps = {
6+
size: "16px",
7+
color: "blue",
8+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const Button = ({ size = "16px", color = "blue" }) => {
2+
return <button style={{ color, fontSize: size }}>Click me</button>;
3+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const Button = ({ size, color }) => {
2+
return <button style={{ color, fontSize: size }}>Click me</button>;
3+
};
4+
5+
Button.defaultProps = {
6+
size: "16px",
7+
color: "blue",
8+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const Button = ({ size = "16px", color = "blue" }) => {
2+
return <button style={{ color, fontSize: size }}>Click me</button>;
3+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const Card = ({ user: { name, age } }) => {
2+
return (
3+
<div>
4+
<p>{name}</p>
5+
<p>{age}</p>
6+
</div>
7+
);
8+
};
9+
10+
Card.defaultProps = {
11+
user: {
12+
name: "Unknown",
13+
age: 0,
14+
},
15+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const Card = ({ user: { name, age } = {
2+
name: "Unknown",
3+
age: 0,
4+
} }) => {
5+
return (
6+
<div>
7+
<p>{name}</p>
8+
<p>{age}</p>
9+
</div>
10+
);
11+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const Span = ({ fontSize, children }) => {
2+
return <span style={{ fontSize }}>{children}</span>;
3+
};
4+
5+
Span.defaultProps = {
6+
fontSize: "20px",
7+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const Span = ({ fontSize = "20px", children }) => {
2+
return <span style={{ fontSize }}>{children}</span>;
3+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const C = (props) => {
2+
return <>{props.text}</>;
3+
};
4+
5+
C.defaultProps = {
6+
text: "test",
7+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const C = (props) => {
2+
return <>{props.text}</>;
3+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const C = ({ text }) => {
2+
return <>{text}</>;
3+
};
4+
5+
C.defaultProps = {
6+
text: "test",
7+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const C = ({ text = "test" }) => {
2+
return <>{text}</>;
3+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const List = ({ items, renderItem }) => {
2+
return <ul>{items.map(renderItem)}</ul>;
3+
};
4+
5+
List.defaultProps = {
6+
items: [],
7+
renderItem: (item) => <li key={item}>{item}</li>,
8+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const List = ({ items = [], renderItem = (item) => <li key={item}>{item}</li> }) => {
2+
return <ul>{items.map(renderItem)}</ul>;
3+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const Link = ({ href, children, ...props }) => {
2+
return (
3+
<a href={href} {...props}>
4+
{children}
5+
</a>
6+
);
7+
};
8+
9+
Link.defaultProps = {
10+
href: "#",
11+
children: "Click here",
12+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const Link = ({ href = "#", children = "Click here", ...props }) => {
2+
return (
3+
<a href={href} {...props}>
4+
{children}
5+
</a>
6+
);
7+
};

0 commit comments

Comments
 (0)