Skip to content

Commit 4d66469

Browse files
committed
Updated PropTypes (#3218)
* Update PropTypes. * Update tests and docs for Router.PropTypes * Change up the default object.
1 parent 1a2798b commit 4d66469

File tree

6 files changed

+28
-17
lines changed

6 files changed

+28
-17
lines changed

docs/Troubleshooting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ You need to add `router` to your component's `contextTypes` to make the router o
66

77
```js
88
contextTypes: {
9-
router: React.PropTypes.object.isRequired
9+
router: Router.PropTypes.router
1010
}
1111
```
1212

docs/guides/ConfirmingNavigation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ You can prevent a transition from happening or prompt the user before leaving a
66
const Home = React.createClass({
77

88
contextTypes: {
9-
router: React.PropTypes.object
9+
router: Router.PropTypes.router
1010
},
1111

1212
componentDidMount() {

modules/PropTypes.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ export function falsy(props, propName, componentName) {
99

1010
export const history = shape({
1111
listen: func.isRequired,
12-
pushState: func.isRequired,
13-
replaceState: func.isRequired,
14-
go: func.isRequired
12+
push: func.isRequired,
13+
replace: func.isRequired,
14+
go: func.isRequired,
15+
goBack: func.isRequired,
16+
goForward: func.isRequired
1517
})
1618

1719
export const location = shape({
@@ -27,11 +29,18 @@ export const components = oneOfType([ component, object ])
2729
export const route = oneOfType([ object, element ])
2830
export const routes = oneOfType([ route, arrayOf(route) ])
2931

32+
export const router = shape({
33+
push: func.isRequired,
34+
replace: func.isRequired,
35+
go: func.isRequired,
36+
goBack: func.isRequired,
37+
goForward: func.isRequired,
38+
setRouteLeaveHook: func.isRequired,
39+
isActive: func.isRequired
40+
})
41+
3042
export default {
31-
falsy,
3243
history,
3344
location,
34-
component,
35-
components,
36-
route
45+
router
3746
}

modules/__tests__/RouterContext-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React from 'react'
33
import { render, unmountComponentAtNode } from 'react-dom'
44

55
import match from '../match'
6+
import { router as routerPropType } from '../PropTypes'
67
import RouterContext from '../RouterContext'
78
import { createRouterObject } from '../RouterUtils'
89

@@ -41,7 +42,7 @@ describe('RouterContext', () => {
4142
}
4243

4344
Component.contextTypes = {
44-
router: React.PropTypes.object.isRequired
45+
router: routerPropType.isRequired
4546
}
4647

4748
routes = { path: '/', component: Component }

modules/__tests__/transitionHooks-test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import expect, { spyOn } from 'expect'
22
import React, { Component } from 'react'
33
import { render, unmountComponentAtNode } from 'react-dom'
44
import createHistory from '../createMemoryHistory'
5+
import { router as routerPropType } from '../PropTypes'
56
import execSteps from './execSteps'
67
import Router from '../Router'
78

@@ -42,7 +43,7 @@ describe('When a router enters a branch', function () {
4243
}
4344

4445
NewsFeed.contextTypes = {
45-
router: React.PropTypes.object.isRequired
46+
router: routerPropType.isRequired
4647
}
4748

4849
class Inbox extends Component {
@@ -71,7 +72,7 @@ describe('When a router enters a branch', function () {
7172
}
7273

7374
User.contextTypes = {
74-
router: React.PropTypes.object.isRequired
75+
router: routerPropType.isRequired
7576
}
7677

7778
NewsFeedRoute = {

upgrade-guides/v2.0.0.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Access `location` from `this.props.location` of your `Route` component. If you'd
112112
// v2.0.x
113113
const RouteComponent = React.createClass({
114114
childContextTypes: {
115-
location: React.PropTypes.object
115+
location: Router.PropTypes.location
116116
},
117117

118118
getChildContext() {
@@ -136,7 +136,7 @@ const RouteComponent = React.createClass({
136136
// 2.0.0
137137
const RouteComponent = React.createClass({
138138
contextTypes: {
139-
route: React.PropTypes.object
139+
route: Router.PropTypes.route
140140
},
141141
getChildContext() {
142142
return {
@@ -160,7 +160,7 @@ const RouteComponent = React.createClass({
160160
// v2.0.0
161161
const RouteComponent = React.createClass({
162162
contextTypes: {
163-
router: React.PropTypes.object.isRequired
163+
router: Router.PropTypes.router.isRequired
164164
},
165165
componentDidMount() {
166166
const { route } = this.props
@@ -204,7 +204,7 @@ const RouteComponent = React.createClass({
204204
// v2.0.0
205205
const RouteComponent = React.createClass({
206206
contextTypes: {
207-
router: React.PropTypes.object.isRequired
207+
router: Router.PropTypes.router.isRequired
208208
},
209209
someHandler() {
210210
this.context.router.push(...)
@@ -229,7 +229,7 @@ const DeepComponent = React.createClass({
229229
// 1) Use context.router (especially if on the server)
230230
const DeepComponent = React.createClass({
231231
contextTypes: {
232-
router: React.PropTypes.object.isRequired
232+
router: Router.PropTypes.router.isRequired
233233
},
234234
handleSubmit() {
235235
this.context.router.push(...)

0 commit comments

Comments
 (0)