Skip to content

Commit 8bd4f74

Browse files
author
Luke Zapart
committed
Add docs for prefer-read-only-props
1 parent 5870047 commit 8bd4f74

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

docs/rules/prefer-read-only-props.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Enforce that props are read-only (react/prefer-read-only-props)
2+
3+
Using Flow, one can define types for props. This rule enforces that prop types are read-only (covariant).
4+
5+
## Rule Details
6+
7+
The following patterns are considered warnings:
8+
9+
```jsx
10+
type Props = {
11+
name: string,
12+
}
13+
class Hello extends React.Component<Props> {
14+
render () {
15+
return <div>Hello {this.props.name}</div>;
16+
}
17+
}
18+
19+
function Hello(props: {-name: string}) {
20+
return <div>Hello {props.name}</div>;
21+
}
22+
23+
const Hello = (props: {|name: string|}) => (
24+
<div>Hello {props.name}</div>
25+
);
26+
```
27+
28+
The following patterns are **not** considered warnings:
29+
30+
```jsx
31+
type Props = {
32+
+name: string,
33+
}
34+
class Hello extends React.Component<Props> {
35+
render () {
36+
return <div>Hello {this.props.name}</div>;
37+
}
38+
}
39+
40+
function Hello(props: {+name: string}) {
41+
return <div>Hello {props.name}</div>;
42+
}
43+
44+
const Hello = (props: {|+name: string|}) => (
45+
<div>Hello {props.name}</div>
46+
);
47+
```

0 commit comments

Comments
 (0)