Skip to content

Commit 969327f

Browse files
committed
test: add VariableDeclarators cases to rule react/no-unstable-default-props
1 parent 18edb24 commit 969327f

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

packages/plugins/eslint-plugin-react/src/rules/no-unstable-default-props.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ function Component({ items = () => {} }) {
4646
}
4747
```
4848

49+
```tsx
50+
function Component(props) {
51+
const { items = [] } = props;
52+
53+
return <div>{items}</div>;
54+
}
55+
```
56+
4957
### Passing
5058

5159
```tsx
@@ -70,6 +78,15 @@ function Component({ items = noopFunc }) {
7078
}
7179
```
7280

81+
```tsx
82+
const emptyArray = [];
83+
function Component(props) {
84+
const { items = emptyArray } = props;
85+
86+
return <div>{items}</div>;
87+
}
88+
```
89+
7390
```tsx
7491
// primitives are all compared by value, so are safe to be inlined
7592
function Component({ num = 3, str = "foo", bool = true }) {

packages/plugins/eslint-plugin-react/src/rules/no-unstable-default-props.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ ruleTester.run(RULE_NAME, rule, {
128128
return null
129129
}
130130
`,
131+
dedent`
132+
const emptyArray = [];
133+
function Component(props) {
134+
const { items = emptyArray } = props;
135+
136+
return <div>{items}</div>;
137+
}
138+
`,
131139
dedent`export default function NonComponent({ foo = {} }) {}`,
132140
],
133141
invalid: [

0 commit comments

Comments
 (0)