Skip to content

Commit afeabdd

Browse files
committed
docs: update docs
1 parent 3f9e8bf commit afeabdd

File tree

1 file changed

+72
-67
lines changed

1 file changed

+72
-67
lines changed

docs/rules/require-default-props.md

Lines changed: 72 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,21 @@ 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",
205+
"functions": "defaultProps" | "defaultArguments" | "ignore"
206+
// @deprecated Use `functions` option instead.
202207
"ignoreFunctionalComponents": <boolean>,
203-
"forceDefaultPropArguments": <boolean>
204208
}]
205209
...
206210
```
207211

208212
- `enabled`: for enabling the rule. 0=off, 1=warn, 2=error. Defaults to 0.
209213
- `forbidDefaultForRequired`: optional boolean to forbid prop default for a required prop. Defaults to false.
210-
- `ignoreFunctionalComponents`: optional boolean to ignore this rule for functional components. Defaults to false.
211-
- `forceDefaultPropArguments`: optional booolean to assign default to object instead of `defaultProps` for functional components. Defaults to false.
214+
- `classes`: For now, only works with "defaultProps".
215+
- `functions`: "Please help documentation". "defaultArguments" is recommended. We will change it to deafult later. Defaults to "defaultProps".
216+
- `ignoreFunctionalComponents`: optional boolean to ignore this rule for functional components. Defaults to false. Deprecated, use `functions` instead.
212217

213218
### `forbidDefaultForRequired`
214219

@@ -284,71 +289,9 @@ MyStatelessComponent.propTypes = {
284289
};
285290
```
286291

287-
### `ignoreFunctionalComponents`
288-
289-
When set to `true`, ignores this rule for all functional components.
290-
291-
Examples of **incorrect** code for this rule:
292-
293-
```jsx
294-
class Greeting extends React.Component {
295-
render() {
296-
return (
297-
<h1>Hello, {this.props.foo} {this.props.bar}</h1>
298-
);
299-
}
300-
301-
static propTypes = {
302-
foo: PropTypes.string,
303-
bar: PropTypes.string.isRequired
304-
};
305-
306-
static defaultProps = {
307-
foo: "foo",
308-
bar: "bar"
309-
};
310-
}
311-
```
312-
313-
Examples of **correct** code for this rule:
314-
315-
```jsx
316-
function MyStatelessComponent({ foo, bar }) {
317-
return <div>{foo}{bar}</div>;
318-
}
319-
320-
MyStatelessComponent.propTypes = {
321-
foo: PropTypes.string,
322-
bar: PropTypes.string
323-
};
324-
```
325-
326-
```jsx
327-
const MyStatelessComponent = ({ foo, bar }) => {
328-
return <div>{foo}{bar}</div>;
329-
}
330-
331-
MyStatelessComponent.propTypes = {
332-
foo: PropTypes.string,
333-
bar: PropTypes.string
334-
};
335-
```
336-
337-
```jsx
338-
const MyStatelessComponent = function({ foo, bar }) {
339-
return <div>{foo}{bar}</div>;
340-
}
341-
342-
MyStatelessComponent.propTypes = {
343-
foo: PropTypes.string,
344-
bar: PropTypes.string
345-
};
346-
```
347-
348-
### `forceDefaultPropArguments`
292+
### `functions`
349293

350-
When set to `true`, assign default to object instead of `defaultProps` for all
351-
functional components.
294+
"Please help documentation." "defaultArguments" is recommended. We will change it to deafult later.
352295

353296
Examples of **incorrect** code for this rule:
354297

@@ -420,6 +363,68 @@ Hello.propTypes = {
420363
};
421364
```
422365

366+
### `ignoreFunctionalComponents`
367+
368+
When set to `true`, ignores this rule for all functional components.
369+
**Depreacted**, use `functions` instead.
370+
371+
Examples of **incorrect** code for this rule:
372+
373+
```jsx
374+
class Greeting extends React.Component {
375+
render() {
376+
return (
377+
<h1>Hello, {this.props.foo} {this.props.bar}</h1>
378+
);
379+
}
380+
381+
static propTypes = {
382+
foo: PropTypes.string,
383+
bar: PropTypes.string.isRequired
384+
};
385+
386+
static defaultProps = {
387+
foo: "foo",
388+
bar: "bar"
389+
};
390+
}
391+
```
392+
393+
Examples of **correct** code for this rule:
394+
395+
```jsx
396+
function MyStatelessComponent({ foo, bar }) {
397+
return <div>{foo}{bar}</div>;
398+
}
399+
400+
MyStatelessComponent.propTypes = {
401+
foo: PropTypes.string,
402+
bar: PropTypes.string
403+
};
404+
```
405+
406+
```jsx
407+
const MyStatelessComponent = ({ foo, bar }) => {
408+
return <div>{foo}{bar}</div>;
409+
}
410+
411+
MyStatelessComponent.propTypes = {
412+
foo: PropTypes.string,
413+
bar: PropTypes.string
414+
};
415+
```
416+
417+
```jsx
418+
const MyStatelessComponent = function({ foo, bar }) {
419+
return <div>{foo}{bar}</div>;
420+
}
421+
422+
MyStatelessComponent.propTypes = {
423+
foo: PropTypes.string,
424+
bar: PropTypes.string
425+
};
426+
```
427+
423428
## When Not To Use It
424429

425430
If you don't care about using `defaultProps` for your component's props that are not required, you can disable this rule.

0 commit comments

Comments
 (0)