|
| 1 | +/* eslint-disable react/forbid-prop-types,react/no-unused-prop-types */ |
| 2 | +import React from 'react'; |
| 3 | + |
| 4 | +import './main.scss'; |
| 5 | + |
| 6 | +interface DemoProps { |
| 7 | + optionalArray?: [], |
| 8 | + optionalBool: boolean, |
| 9 | + optionalFunc: Function, |
| 10 | + optionalNumber: number, |
| 11 | + optionalObject: object, |
| 12 | + optionalString: string, |
| 13 | + optionalSymbol: symbol, |
| 14 | + |
| 15 | + // Anything that can be rendered: numbers, strings, elements or an array |
| 16 | + // (or fragment) containing these types. |
| 17 | + optionalNode: React.ReactNode, |
| 18 | + |
| 19 | + // A React element (ie. <MyComponent />). |
| 20 | + optionalElement: React.ReactElement, |
| 21 | + |
| 22 | + // A React element type (ie. MyComponent). |
| 23 | + optionalElementType: React.ElementType, |
| 24 | + |
| 25 | + // You can also declare that a prop is an instance of a class. This uses |
| 26 | + // JS's instanceof operator. |
| 27 | + optionalMessage: React.ReactInstance, |
| 28 | + |
| 29 | + // You can ensure that your prop is limited to specific values by treating |
| 30 | + // it as an enum. |
| 31 | + optionalEnum: 'News'|'Photos', |
| 32 | + |
| 33 | + // An object that could be one of many types |
| 34 | + optionalUnion: string|number|React.ReactInstance, |
| 35 | + |
| 36 | + // An array of a certain type |
| 37 | + optionalArrayOf: number[], |
| 38 | + |
| 39 | + // An object with property values of a certain type |
| 40 | + optionalObjectOf: Record<number, any>, |
| 41 | + |
| 42 | + // You can chain any of the above with `isRequired` to make sure a warning |
| 43 | + // is shown if the prop isn't provided. |
| 44 | +} |
| 45 | + |
| 46 | +const Demo = (props: DemoProps) => { |
| 47 | + return <div> Test </div>; |
| 48 | +} |
| 49 | + |
| 50 | +Demo.defaultProps = { |
| 51 | + optionalString: 'optionalString' |
| 52 | +}; |
| 53 | + |
| 54 | +export default Demo; |
0 commit comments