Skip to content

Commit fc43b0a

Browse files
committed
chore(docs): improve documentation
1 parent 1e20b43 commit fc43b0a

File tree

1 file changed

+49
-8
lines changed

1 file changed

+49
-8
lines changed

docs/rules/require-default-props.md

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,7 @@ NotAComponent.propTypes = {
199199
...
200200
"react/require-default-props": [<enabled>, {
201201
"forbidDefaultForRequired": <boolean>,
202-
// For now, this wouldn't support any other choices, and would be optional,
203-
// but later could be set to "ignore" as long as `functions` wasn't set to "ignore"
204-
"classes": "defaultProps",
202+
"classes": "defaultProps | "ignore",
205203
"functions": "defaultProps" | "defaultArguments" | "ignore"
206204
// @deprecated Use `functions` option instead.
207205
"ignoreFunctionalComponents": <boolean>,
@@ -211,8 +209,8 @@ NotAComponent.propTypes = {
211209
212210
- `enabled`: for enabling the rule. 0=off, 1=warn, 2=error. Defaults to 0.
213211
- `forbidDefaultForRequired`: optional boolean to forbid prop default for a required prop. Defaults to false.
214-
- `classes`: For now, only works with "defaultProps".
215-
- `functions`: optional string that this rule determines strategy for the function. "defaultArguments" is recommended. We will change it to deafult later. Defaults to "defaultProps".
212+
- `classes`: optional string to determine which strategy a class component uses for defaulting props. Defaults to "defaultProps".
213+
- `functions`: optional string to determine which strategy a functional component uses for defaulting props. "defaultArguments" is recommended. We will change it to deafult later. Defaults to "defaultProps".
216214
- `ignoreFunctionalComponents`: optional boolean to ignore this rule for functional components. Defaults to false. Deprecated, use `functions` instead.
217215
218216
### `forbidDefaultForRequired`
@@ -289,15 +287,58 @@ MyStatelessComponent.propTypes = {
289287
};
290288
```
291289
290+
### `classes`
291+
292+
- "defaultProps": Use `.defaultProps`. It's default.
293+
- "ignore": Ignore this rule for class components.
294+
295+
Examples of **incorrect** code for this rule, when set to `defaultProps`:
296+
297+
```jsx
298+
class Greeting extends React.Component {
299+
render() {
300+
return (
301+
<h1>Hello, {this.props.foo} {this.props.bar}</h1>
302+
);
303+
}
304+
305+
static propTypes = {
306+
foo: PropTypes.string,
307+
bar: PropTypes.string.isRequired
308+
};
309+
}
310+
```
311+
312+
Examples of **correct** code for this rule, when set to `defaultProps`:
313+
314+
```jsx
315+
class Greeting extends React.Component {
316+
render() {
317+
return (
318+
<h1>Hello, {this.props.foo} {this.props.bar}</h1>
319+
);
320+
}
321+
322+
static propTypes = {
323+
foo: PropTypes.string,
324+
bar: PropTypes.string.isRequired
325+
};
326+
327+
static defaultProps = {
328+
foo: "foo"
329+
};
330+
}
331+
```
332+
292333
### `functions`
293334
294-
- "defaultProps": Use `.defaultProps`.
335+
- "defaultProps": Use `.defaultProps`. It's default.
295336
- "defaultArguments": Use object default arguments
296337
- "ignore": Ignore this rule for functional components.
297338
298339
"defaultArguments" is recommended. We will change it to deafult later.
299340
300-
Examples of **incorrect** code for this rule:
341+
Examples of **incorrect** code for this rule, when set to `defaultArguments`:
301342
302343
```jsx
303344
function Hello({ foo }) {
@@ -335,7 +376,7 @@ Hello.propTypes = {
335376
};
336377
```
337378
338-
Examples of **correct** code for this rule:
379+
Examples of **correct** code for this rule, when set to `defaultArguments`:
339380
340381
```jsx
341382
function Hello({ foo = 'foo' }) {

0 commit comments

Comments
 (0)