Skip to content

Commit c9f38c9

Browse files
committed
docs: add router state blurb
1 parent 8d92a45 commit c9f38c9

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
React standard library.
44

55
- Collection of React goodies necessary for every project.
6-
- Isomorphic - all components work in browser and Node.
7-
- [See demos and docs](https://mailonline.github.io/mol-fe-react/)
6+
- Isomorphic - all components work in browser and Node.js (and some in `react-native`).
7+
- [See demos and docs](https://mailonline.github.io/mol-fe-react/).
88

99
## Installation
1010

@@ -37,16 +37,18 @@ const MyComponent = mock();
3737
- [`<NetworkSensor>`](./docs/NetworkSensor.md) and [`withNetwork()`](./docs/NetworkSensor.md#withnetwork)
3838
- [`<LightSensor>`](./docs/LightSensor.md)
3939
- [`<LocationSensor>`](./docs/LocationSensor.md)
40-
- [`<SizeSensor>`](./docs/SizeSensor.md)
4140
- [`<ScrollSensor>`](./docs/ScrollSensor.md)
41+
- [`<SizeSensor>`](./docs/SizeSensor.md)
42+
- `<ViewportSensor>`
4243
- [`<WidthSensor>`](./docs/WidthSensor.md)
43-
- [`<WindowSizeSensor>`](./docs/WindowSizeSensor.md)
4444
- [`<WindowScrollSensor>`](./docs/WindowScrollSensor.md)
45+
- [`<WindowSizeSensor>`](./docs/WindowSizeSensor.md)
4546
- Generators
4647
- [`<Audio>`](./docs/Audio.md)
4748
- [`<LocalStorage>`](./docs/LocalStorage.md)
4849
- [`<Speak>`](./docs/Speak.md)
4950
- [`<Vibrate>`](./docs/Vibrate.md)
51+
- `<Video>`
5052
- Context
5153
- [`<Provider>`](./docs/context.md#provider), [`<Consumer>`](./docs/context.md#consumer), and [`withContext()`](./docs/context.md#withcontext)
5254
- [`<Theme>`](./docs/theme.md#theme), [`<Themed>`](./docs/theme.md#themed), and [`withTheme()`](./docs/theme.md#withtheme)

docs/route.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Routing components allow you to create implement single page app routing functionality.
44

5+
- Provides *dynamic* routing, [just like `react-router`](https://reacttraining.com/react-router/core/guides/philosophy/dynamic-routing)
6+
- Use any state container
7+
- Multiple routers on one page
8+
59
Contents:
610

711
- [`<Router>`](#router)
@@ -10,6 +14,46 @@ Contents:
1014
- [`withRoute()`](#withroute)
1115

1216

17+
## Use any state container
18+
19+
With libreact's `<Router>` you can choose to store the current route in your state continer (like Redux or MobX) of
20+
choice, or not bother about it at all, in which case the `<Router>` will just use the current browser location out-of-the box.
21+
22+
The "problem-of-routers" is that they all want to be the ones that keep the state of the route. For example, [`react-router`](https://reacttraining.com/react-router/) uses
23+
its internal history objects to store route information, and [it does not give you good access to that data structure](http://formidable.com/blog/2016/07/11/let-the-url-do-the-talking-part-1-the-pain-of-react-router-in-redux/).
24+
25+
So, if you wanted to store the state of the route in Redux, there was no good way for you to do that using `react-router`, that is why
26+
[`redux-little-router`](https://github.com/FormidableLabs/redux-little-router) was born, however, `redux-little-router` itself hoards the
27+
state of the route in Redux, so you cannot use it if you use any other state container, say MobX.
28+
29+
Libreact is completely orthogonal to where you store the current route, all you have to do is provide the current route to the `<Router>` component:
30+
31+
```jsx
32+
<Router route={currentRoute}>
33+
{/* ... */}
34+
</Router>
35+
```
36+
37+
You can story in Redux or MobX, or really anywhere you want. And if you don't want to bother, don't! Just use the current location of the browser:
38+
39+
```jsx
40+
<LocationSensor>{({pathname}) =>
41+
<Router route={pathname}>
42+
{/* ... */}
43+
</Router>
44+
}</LocationSensor>
45+
```
46+
47+
Actually, you don't even have to do that, if you don't explicitly specify the `route` prop, the `<Router>` component will do exactly that for you under the hood,
48+
so, simply use:
49+
50+
```jsx
51+
<Router>
52+
{/* ... */}
53+
</Router>
54+
```
55+
56+
1357
## `<Router>`
1458

1559
`Router` is a root component that provides routing to your application. I should be placed above all other components

0 commit comments

Comments
 (0)