File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
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
+ ```
You can’t perform that action at this time.
0 commit comments