@@ -5,6 +5,80 @@ To see discussion around these API changes, please refer to the
5
5
[ changelog] ( /CHANGELOG.md ) and visit the commits and issues they
6
6
reference.
7
7
8
+ 0.12.x -> 0.13.x
9
+ ----------------
10
+
11
+ React introduced the ability to use ES6 classes for component
12
+ definitions, which has the side-effect of mixins not being "the thing"
13
+ anymore. Our mixins like ` State ` and ` Navigation ` just proxied calls to
14
+ some methods on an undocumented feature of React called ` context ` , that
15
+ in turn called methods on the router instance under the hood.
16
+
17
+ Without mixins we needed a way for you to get access to these methods.
18
+ We decided the simplest solution was to stop hiding the router instance
19
+ and just put the whole thing on context.
20
+
21
+ You can think about context as values that are floating around a render
22
+ tree that parent components (` Handler ` in the ` Router.run ` callback) can
23
+ explicitly define and descendent components can explicitly ask for. The
24
+ stuff on context doesn't show up in a component unless you ask for it.
25
+
26
+ ``` js
27
+ // 0.12.x
28
+ var Foo = React .createClass ({
29
+ mixins: [ Router .State ],
30
+ render : function () {
31
+ var id = this .getParams ().id ;
32
+ var searchTerm = this .getQuery ().searchTerm ;
33
+ // etc. ...
34
+ }
35
+ });
36
+
37
+ // 0.13.x w/o ES6 fanciness
38
+ var Foo = React .createClass ({
39
+ contextTypes: {
40
+ router: React .PropTypes .func
41
+ },
42
+
43
+ render : function () {
44
+ var router = this .context .router ;
45
+ var id = router .getCurrentParams ().id ;
46
+ var searchTerm = touer .getCurrentQuery ().searchTerm ;
47
+ // etc.
48
+ }
49
+ });
50
+
51
+ // 0.13.x w/ ES6 fanciness
52
+ class Foo extends React .Component {
53
+ render () {
54
+ var { router } = this .context ;
55
+ var id = router .getCurrentParams ().id ;
56
+ var searchTerm = touer .getCurrentQuery ().searchTerm ;
57
+ // etc.
58
+ }
59
+ }
60
+
61
+ Foo .contextTypes = {
62
+ router: React .PropTypes .func
63
+ };
64
+ ```
65
+
66
+ Most of the time we prefer to just pass the state down the props tree
67
+ and not mess with context:
68
+
69
+ ``` js
70
+ Router .run (routes, (Handler , state ) => {
71
+ React .render (< Handler {... state}/ > , document .body );
72
+ });
73
+
74
+ // and then when rendering route handlers, keep passing it down
75
+ < RouteHandler {... this .props }/ >
76
+
77
+ // and then in your methods you have what you need on props
78
+ var id = this .props .params .id ;
79
+ var searchTerm = this .props .query .searchTerm ;
80
+ ```
81
+
8
82
0.11.x -> 0.12.0
9
83
----------------
10
84
0 commit comments