Skip to content

Commit 02e2a35

Browse files
committed
Update to final component-based context API
1 parent a96a042 commit 02e2a35

File tree

12 files changed

+129
-49
lines changed

12 files changed

+129
-49
lines changed

packages/react-router-config/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646
"jest": "^22.1.4",
4747
"pretty-bytes": "^4.0.2",
4848
"raf": "^3.4.0",
49-
"react": "^16.2.0",
49+
"react": "^16.3.0-alpha.0",
5050
"react-addons-test-utils": "^15.6.2",
51-
"react-dom": "^16.2.0",
51+
"react-dom": "^16.3.0-alpha.0",
5252
"react-router": "^4.2.0",
5353
"rollup": "^0.50.1",
5454
"rollup-plugin-babel": "^3.0.3",

packages/react-router-dom/modules/Link.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,29 @@ class Link extends React.Component {
4949

5050
invariant(to !== undefined, 'You must specify the "to" property');
5151

52-
return RouterContext.consume(({ router }) => {
53-
invariant(router, "You should not use <Link> outside a <Router>");
52+
return (
53+
<RouterContext.Consumer>
54+
{({ router }) => {
55+
invariant(router, "You should not use <Link> outside a <Router>");
5456

55-
const { history } = router;
56-
const location =
57-
typeof to === "string"
58-
? createLocation(to, null, null, history.location)
59-
: to;
57+
const { history } = router;
58+
const location =
59+
typeof to === "string"
60+
? createLocation(to, null, null, history.location)
61+
: to;
6062

61-
const href = history.createHref(location);
62-
return (
63-
<a
64-
{...props}
65-
onClick={this.handleClick(history)}
66-
href={href}
67-
ref={innerRef}
68-
/>
69-
);
70-
});
63+
const href = history.createHref(location);
64+
return (
65+
<a
66+
{...props}
67+
onClick={this.handleClick(history)}
68+
href={href}
69+
ref={innerRef}
70+
/>
71+
);
72+
}}
73+
</RouterContext.Consumer>
74+
);
7175
}
7276
}
7377

packages/react-router-dom/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@
6565
"jest": "^22.1.4",
6666
"pretty-bytes": "^4.0.2",
6767
"raf": "^3.4.0",
68-
"react": "^16.2.0",
68+
"react": "^16.3.0-alpha.0",
6969
"react-addons-test-utils": "^15.6.2",
70-
"react-dom": "^16.2.0",
70+
"react-dom": "^16.3.0-alpha.0",
7171
"rollup": "^0.50.1",
7272
"rollup-plugin-babel": "^3.0.3",
7373
"rollup-plugin-commonjs": "^8.2.6",

packages/react-router/modules/Prompt.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ class InnerPrompt extends React.Component {
6262
}
6363
}
6464

65-
const Prompt = props =>
66-
RouterContext.consume(({ router }) => (
67-
<InnerPrompt {...props} router={router} />
68-
));
65+
const Prompt = props => (
66+
<RouterContext.Consumer>
67+
{({ router }) => <InnerPrompt {...props} router={router} />}
68+
</RouterContext.Consumer>
69+
);
6970

7071
export default Prompt;

packages/react-router/modules/Redirect.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ class InnerRedirect extends React.Component {
9393
}
9494
}
9595

96-
const Redirect = props =>
97-
RouterContext.consume(({ router }) => (
98-
<InnerRedirect {...props} router={router} />
99-
));
96+
const Redirect = props => (
97+
<RouterContext.Consumer>
98+
{({ router }) => <InnerRedirect {...props} router={router} />}
99+
</RouterContext.Consumer>
100+
);
100101

101102
export default Redirect;

packages/react-router/modules/Route.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,18 @@ class InnerRoute extends React.Component {
137137
}
138138

139139
render() {
140-
return RouterContext.provide(this.getChildContext(), this.renderChildren());
140+
return (
141+
<RouterContext.Provider value={this.getChildContext()}>
142+
{this.renderChildren()}
143+
</RouterContext.Provider>
144+
);
141145
}
142146
}
143147

144-
const Route = props =>
145-
RouterContext.consume(({ router }) => (
146-
<InnerRoute {...props} router={router} />
147-
));
148+
const Route = props => (
149+
<RouterContext.Consumer>
150+
{({ router }) => <InnerRoute {...props} router={router} />}
151+
</RouterContext.Consumer>
152+
);
148153

149154
export default Route;

packages/react-router/modules/Router.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,10 @@ class Router extends React.Component {
7575

7676
render() {
7777
const { children } = this.props;
78-
return RouterContext.provide(
79-
this.getChildContext(),
80-
children ? React.Children.only(children) : null
78+
return (
79+
<RouterContext.Provider value={this.getChildContext()}>
80+
{children ? React.Children.only(children) : null}
81+
</RouterContext.Provider>
8182
);
8283
}
8384
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
22

3-
const RouterContext = React.unstable_createContext({});
3+
const RouterContext = React.createContext({});
44

55
export default RouterContext;

packages/react-router/modules/Switch.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ class InnerSwitch extends React.Component {
6666
}
6767
}
6868

69-
const Switch = props =>
70-
RouterContext.consume(({ router }) => (
71-
<InnerSwitch {...props} router={router} />
72-
));
69+
const Switch = props => (
70+
<RouterContext.Consumer>
71+
{({ router }) => <InnerSwitch {...props} router={router} />}
72+
</RouterContext.Consumer>
73+
);
7374

7475
export default Switch;

packages/react-router/modules/__tests__/Router-test.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,14 @@ describe("A <Router>", () => {
5151

5252
describe("context", () => {
5353
let rootContext;
54-
const ContextChecker = () =>
55-
RouterContext.consume(context => {
56-
rootContext = context;
57-
return null;
58-
});
54+
const ContextChecker = () => (
55+
<RouterContext.Consumer>
56+
{context => {
57+
rootContext = context;
58+
return null;
59+
}}
60+
</RouterContext.Consumer>
61+
);
5962

6063
afterEach(() => {
6164
rootContext = undefined;

packages/react-router/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@
6262
"jest": "^22.1.4",
6363
"pretty-bytes": "^4.0.2",
6464
"raf": "^3.4.0",
65-
"react": "^16.2.0",
65+
"react": "^16.3.0-alpha.0",
6666
"react-addons-test-utils": "^15.6.2",
67-
"react-dom": "^16.2.0",
67+
"react-dom": "^16.3.0-alpha.0",
6868
"rollup": "^0.50.1",
6969
"rollup-plugin-babel": "^3.0.3",
7070
"rollup-plugin-commonjs": "^8.2.6",

website/package-lock.json

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)