forked from remix-run/react-router
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPropTypes.js
78 lines (64 loc) · 2.4 KB
/
PropTypes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { PropTypes } from 'react'
import deprecateObjectProperties from './deprecateObjectProperties'
import * as InternalPropTypes from './InternalPropTypes'
import warning from './routerWarning'
const { func, object, shape, string } = PropTypes
export const routerShape = shape({
push: func.isRequired,
replace: func.isRequired,
go: func.isRequired,
goBack: func.isRequired,
goForward: func.isRequired,
setRouteLeaveHook: func.isRequired,
isActive: func.isRequired
})
export const locationShape = shape({
pathname: string.isRequired,
search: string.isRequired,
state: object,
action: string.isRequired,
key: string
})
// Deprecated stuff below:
export let falsy = InternalPropTypes.falsy
export let history = InternalPropTypes.history
export let location = locationShape
export let component = InternalPropTypes.component
export let components = InternalPropTypes.components
export let route = InternalPropTypes.route
export let routes = InternalPropTypes.routes
export let router = routerShape
if (__DEV__) {
const deprecatePropType = (propType, message) => (...args) => {
warning(false, message)
return propType(...args)
}
const deprecateInternalPropType = propType => (
deprecatePropType(propType, 'This prop type is not intended for external use, and was previously exported by mistake. These internal prop types are deprecated for external use, and will be removed in a later version.')
)
const deprecateRenamedPropType = (propType, name) => (
deprecatePropType(propType, `The \`${name}\` prop type is now exported as \`${name}Shape\` to avoid name conflicts. This export is deprecated and will be removed in a later version.`)
)
falsy = deprecateInternalPropType(falsy)
history = deprecateInternalPropType(history)
component = deprecateInternalPropType(component)
components = deprecateInternalPropType(components)
route = deprecateInternalPropType(route)
routes = deprecateInternalPropType(routes)
location = deprecateRenamedPropType(location, 'location')
router = deprecateRenamedPropType(router, 'router')
}
let defaultExport = {
falsy,
history,
location,
component,
components,
route,
// For some reason, routes was never here.
router
}
if (__DEV__) {
defaultExport = deprecateObjectProperties(defaultExport, 'The default export from `react-router/lib/PropTypes` is deprecated. Please use the named exports instead.')
}
export default defaultExport