Skip to content

Commit 5a2bcdd

Browse files
committed
Make Prompt use the new API
1 parent 355d82a commit 5a2bcdd

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

packages/react-router/modules/Prompt.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
11
import React from "react";
22
import PropTypes from "prop-types";
33
import invariant from "invariant";
4+
import RouterContext from "./RouterContext";
45

56
/**
67
* The public API for prompting the user before navigating away
78
* from a screen with a component.
89
*/
9-
class Prompt extends React.Component {
10+
class InnerPrompt extends React.Component {
1011
static propTypes = {
1112
when: PropTypes.bool,
12-
message: PropTypes.oneOfType([PropTypes.func, PropTypes.string]).isRequired
13-
};
14-
15-
static defaultProps = {
16-
when: true
17-
};
18-
19-
static contextTypes = {
13+
message: PropTypes.oneOfType([PropTypes.func, PropTypes.string]).isRequired,
2014
router: PropTypes.shape({
2115
history: PropTypes.shape({
2216
block: PropTypes.func.isRequired
2317
}).isRequired
2418
}).isRequired
2519
};
2620

21+
static defaultProps = {
22+
when: true
23+
};
24+
2725
enable(message) {
2826
if (this.unblock) this.unblock();
2927

30-
this.unblock = this.context.router.history.block(message);
28+
this.unblock = this.props.router.history.block(message);
3129
}
3230

3331
disable() {
@@ -39,7 +37,7 @@ class Prompt extends React.Component {
3937

4038
componentWillMount() {
4139
invariant(
42-
this.context.router,
40+
this.props.router,
4341
"You should not use <Prompt> outside a <Router>"
4442
);
4543

@@ -64,4 +62,9 @@ class Prompt extends React.Component {
6462
}
6563
}
6664

65+
const Prompt = props =>
66+
RouterContext.consume(({ router }) => (
67+
<InnerPrompt {...props} router={router} />
68+
));
69+
6770
export default Prompt;

0 commit comments

Comments
 (0)