(workInProgress, Component)
| 20204 | } |
| 20205 | |
| 20206 | function validateFunctionComponentInDev(workInProgress, Component) { |
| 20207 | { |
| 20208 | if (Component) { |
| 20209 | if (Component.childContextTypes) { |
| 20210 | error('%s(...): childContextTypes cannot be defined on a function component.', Component.displayName || Component.name || 'Component'); |
| 20211 | } |
| 20212 | } |
| 20213 | |
| 20214 | if (workInProgress.ref !== null) { |
| 20215 | var info = ''; |
| 20216 | var ownerName = getCurrentFiberOwnerNameInDevOrNull(); |
| 20217 | |
| 20218 | if (ownerName) { |
| 20219 | info += '\n\nCheck the render method of `' + ownerName + '`.'; |
| 20220 | } |
| 20221 | |
| 20222 | var warningKey = ownerName || ''; |
| 20223 | var debugSource = workInProgress._debugSource; |
| 20224 | |
| 20225 | if (debugSource) { |
| 20226 | warningKey = debugSource.fileName + ':' + debugSource.lineNumber; |
| 20227 | } |
| 20228 | |
| 20229 | if (!didWarnAboutFunctionRefs[warningKey]) { |
| 20230 | didWarnAboutFunctionRefs[warningKey] = true; |
| 20231 | |
| 20232 | error('Function components cannot be given refs. ' + 'Attempts to access this ref will fail. ' + 'Did you mean to use React.forwardRef()?%s', info); |
| 20233 | } |
| 20234 | } |
| 20235 | |
| 20236 | if ( Component.defaultProps !== undefined) { |
| 20237 | var componentName = getComponentNameFromType(Component) || 'Unknown'; |
| 20238 | |
| 20239 | if (!didWarnAboutDefaultPropsOnFunctionComponent[componentName]) { |
| 20240 | error('%s: Support for defaultProps will be removed from function components ' + 'in a future major release. Use JavaScript default parameters instead.', componentName); |
| 20241 | |
| 20242 | didWarnAboutDefaultPropsOnFunctionComponent[componentName] = true; |
| 20243 | } |
| 20244 | } |
| 20245 | |
| 20246 | if (typeof Component.getDerivedStateFromProps === 'function') { |
| 20247 | var _componentName3 = getComponentNameFromType(Component) || 'Unknown'; |
| 20248 | |
| 20249 | if (!didWarnAboutGetDerivedStateOnFunctionComponent[_componentName3]) { |
| 20250 | error('%s: Function components do not support getDerivedStateFromProps.', _componentName3); |
| 20251 | |
| 20252 | didWarnAboutGetDerivedStateOnFunctionComponent[_componentName3] = true; |
| 20253 | } |
| 20254 | } |
| 20255 | |
| 20256 | if (typeof Component.contextType === 'object' && Component.contextType !== null) { |
| 20257 | var _componentName4 = getComponentNameFromType(Component) || 'Unknown'; |
| 20258 | |
| 20259 | if (!didWarnAboutContextTypeOnFunctionComponent[_componentName4]) { |
| 20260 | error('%s: Function components do not support contextType.', _componentName4); |
| 20261 | |
| 20262 | didWarnAboutContextTypeOnFunctionComponent[_componentName4] = true; |
| 20263 | } |
no test coverage detected
searching dependent graphs…