Skip to content

Commit 11dee1f

Browse files
committed
Update the docs for React 0.14
1 parent 2d3d0be commit 11dee1f

File tree

5 files changed

+46
-30
lines changed

5 files changed

+46
-30
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
All notable changes are described on the [Releases](https://github.com/gaearon/react-redux/releases) page.
1+
All notable changes are described on the [Releases](https://github.com/rackt/react-redux/releases) page.

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ Performant and flexible.
1515
npm install --save react-redux
1616
```
1717

18-
React Redux requires **React 0.13 or later.**
18+
React Redux requires **React 0.14 or later.**
1919

2020
## React Native
2121

22-
What you get from `react-redux` is for React.
23-
For React Native, import from `react-redux/native` instead.
22+
Until [React Native is compatible with React 0.14](https://github.com/facebook/react-native/issues/2985), you’ll need to keep using [React Redux 3.x branch and documentation](https://github.com/rackt/react-redux/tree/v3.1.0).
2423

2524
## Documentation
2625

docs/api.md

+30-14
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@
22

33
### `<Provider store>`
44

5-
Makes the Redux store available to the `connect()` calls in the component hierarchy below. Normally, you can’t use `connect()` without wrapping the root component in `<Provider>`. (If you *really* need to, you can manually pass `store` as a prop to every `connect()`ed component, but we only recommend to do this for stubbing `store` in unit tests, or in non-fully-React codebases. Normally, you should just use `<Provider>`.)
5+
Makes the Redux store available to the `connect()` calls in the component hierarchy below. Normally, you can’t use `connect()` without wrapping the root component in `<Provider>`.
6+
7+
If you *really* need to, you can manually pass `store` as a prop to every `connect()`ed component, but we only recommend to do this for stubbing `store` in unit tests, or in non-fully-React codebases. Normally, you should just use `<Provider>`.
68

79
#### Props
810

9-
* `store`: (*[Redux Store](http://gaearon.github.io/redux/docs/api/Store.html)*): The single Redux store in your application.
10-
* `children`: (*Function*): Unlike most React components, `<Provider>` accepts a [function as a child](#child-must-be-a-function) with your root component. This is a temporary workaround for a React 0.13 context issue, which will be fixed when React 0.14 comes out.
11+
* `store` (*[Redux Store](http://rackt.github.io/redux/docs/api/Store.html)*): The single Redux store in your application.
12+
* `children` (*ReactElement*) The root of your component hierarchy.
1113

1214
#### Example
1315

1416
##### Vanilla React
1517

1618
```js
17-
React.render(
19+
ReactDOM.render(
1820
<Provider store={store}>
19-
{() => <MyRootComponent />}
21+
<MyRootComponent />
2022
</Provider>,
2123
rootEl
2224
);
@@ -26,9 +28,10 @@ React.render(
2628

2729
```js
2830
Router.run(routes, Router.HistoryLocation, (Handler, routerState) => { // note "routerState" here
29-
React.render(
31+
ReactDOM.render(
3032
<Provider store={store}>
31-
{() => <Handler routerState={routerState} />} // note "routerState" here: important to pass it down
33+
{/* note "routerState" here: important to pass it down */}
34+
<Handler routerState={routerState} />
3235
</Provider>,
3336
document.getElementById('root')
3437
);
@@ -38,9 +41,9 @@ Router.run(routes, Router.HistoryLocation, (Handler, routerState) => { // note "
3841
##### React Router 1.0
3942

4043
```js
41-
React.render(
44+
ReactDOM.render(
4245
<Provider store={store}>
43-
{() => <Router history={history}>...</Router>}
46+
<Router history={history}>...</Router>
4447
</Provider>,
4548
targetEl
4649
);
@@ -57,26 +60,39 @@ Instead, it *returns* a new, connected component class, for you to use.
5760

5861
* [`mapStateToProps(state, [ownProps]): stateProps`] \(*Function*): If specified, the component will subscribe to Redux store updates. Any time it updates, `mapStateToProps` will be called. Its result must be a plain object, and it will be merged into the component’s props. If you omit it, the component will not be subscribed to the Redux store. If `ownProps` is specified as a second argument, its value will be the properties passed to your component, and `mapStateToProps` will be re-invoked whenever the component receives new props.
5962

60-
* [`mapDispatchToProps(dispatch, [ownProps]): dispatchProps`] \(*Object* or *Function*): If an object is passed, each function inside it will be assumed to be a Redux action creator. An object with the same function names, but bound to a Redux store, will be merged into the component’s props. If a function is passed, it will be given `dispatch`. It’s up to you to return an object that somehow uses `dispatch` to bind action creators in your own way. (Tip: you may use the [`bindActionCreators()`](http://gaearon.github.io/redux/docs/api/bindActionCreators.html) helper from Redux.) If you omit it, the default implementation just injects `dispatch` into your component’s props. If `ownProps` is specified as a second argument, its value will be the properties passed to your component, and `mapDispatchToProps` will be re-invoked whenever the component receives new props.
63+
* [`mapDispatchToProps(dispatch, [ownProps]): dispatchProps`] \(*Object* or *Function*): If an object is passed, each function inside it will be assumed to be a Redux action creator. An object with the same function names, but bound to a Redux store, will be merged into the component’s props. If a function is passed, it will be given `dispatch`. It’s up to you to return an object that somehow uses `dispatch` to bind action creators in your own way. (Tip: you may use the [`bindActionCreators()`](http://rackt.github.io/redux/docs/api/bindActionCreators.html) helper from Redux.) If you omit it, the default implementation just injects `dispatch` into your component’s props. If `ownProps` is specified as a second argument, its value will be the properties passed to your component, and `mapDispatchToProps` will be re-invoked whenever the component receives new props.
6164

6265
* [`mergeProps(stateProps, dispatchProps, ownProps): props`] \(*Function*): If specified, it is passed the result of `mapStateToProps()`, `mapDispatchToProps()`, and the parent `props`. The plain object you return from it will be passed as props to the wrapped component. You may specify this function to select a slice of the state based on props, or to bind action creators to a particular variable from props. If you omit it, `Object.assign({}, ownProps, stateProps, dispatchProps)` is used by default.
6366

6467
* [`options`] *(Object)* If specified, further customizes the behavior of the connector.
65-
* [`pure`] *(Boolean)*: If true, implements `shouldComponentUpdate` and shallowly compares the result of `mergeProps`, preventing unnecessary updates, assuming that the component is a “pure” component and does not rely on any input or state other than its props and the selected Redux store’s state. *Defaults to `true`.*
68+
* [`pure = true`] *(Boolean)*: If true, implements `shouldComponentUpdate` and shallowly compares the result of `mergeProps`, preventing unnecessary updates, assuming that the component is a “pure” component and does not rely on any input or state other than its props and the selected Redux store’s state. *Defaults to `true`.*
69+
* [`withRef = false`] *(Boolean)*: If true, stores a ref to the wrapped component instance and makes it available via `getWrappedInstance()` method. *Defaults to `false`.*
6670

6771
#### Returns
6872

6973
A React component class that injects state and action creators into your component according to the specified options.
7074

75+
##### Static Properties
76+
77+
* `WrappedComponent` *(Component)*: The original component class passed to `connect()`.
78+
79+
##### Static Methods
80+
81+
All the original static methods of the component are hoisted.
82+
83+
##### Instance Methods
84+
85+
###### `getWrappedInstance(): ReactComponent`
86+
87+
Returns the wrapped component instance. Only available if you pass `{ withRef: true }` as part of the `connect()`’s fourth `options` argument.
88+
7189
#### Remarks
7290

7391
* It needs to be invoked two times. The first time with its arguments described above, and a second time, with the component: `connect(mapStateToProps, mapDispatchToProps, mergeProps)(MyComponent)`.
7492

7593
* It does not modify the passed React component. It returns a new, connected component, that you should use instead.
7694

77-
* The `mapStateToProps` function takes a single argument of the entire Redux store’s state and returns an object to be passed as props. It is often called a **selector**. Use [reselect](https://github.com/faassen/reselect) to efficiently compose selectors and [compute derived data](http://gaearon.github.io/redux/docs/recipes/ComputingDerivedData.html).
78-
79-
* **To use `connect()`, the root component of your app must be wrapped into `<Provider>{() => ... }</Provider>` before being rendered.** You may also pass `store` as a prop to the `connect()`ed component, but it's not recommended, because it's just too much trouble. Only do this for non-fully-React codebases or to stub the store in a unit test.
95+
* The `mapStateToProps` function takes a single argument of the entire Redux store’s state and returns an object to be passed as props. It is often called a **selector**. Use [reselect](https://github.com/rackt/reselect) to efficiently compose selectors and [compute derived data](http://rackt.github.io/redux/docs/recipes/ComputingDerivedData.html).
8096

8197
#### Examples
8298

docs/quick-start.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,10 @@ This is the most basic usage, but `connect()` supports many other patterns: just
126126

127127
Finally, how do we actually hook it up to the Redux store? We need to create the store somewhere at the root of our component hierarchy. For client apps, the root component is a good place. For server rendering, you can do this in the request handler.
128128

129-
The trick is to wrap the whole view hierarchy into a `<Provider>{() => ... }</Provider>` where `Provider` is imported from `react-redux`. One gotcha is that **the child of `Provider` must be a function**. This is to work around an issue about how context (undocumented feature we have to rely on to pass Redux data to components below) works in React 0.13. In React 0.14, you will be able to put your view hierarchy in `<Provider>` without wrapping it into a function.
129+
The trick is to wrap the whole view hierarchy into a `<Provider>` from React Redux.
130130

131131
```js
132+
import ReactDOM from 'react-dom';
132133
import { Component } from 'react';
133134
import { Provider } from 'react-redux';
134135

@@ -140,9 +141,10 @@ class App extends Component {
140141

141142
const targetEl = document.getElementById('root');
142143

143-
React.render((
144+
ReactDOM.render(
144145
<Provider store={store}>
145-
{() => <App />}
146-
</Provider>
147-
), targetEl);
146+
<App />
147+
</Provider>,
148+
targetEl
149+
);
148150
```

docs/troubleshooting.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ Root view:
1818

1919
```js
2020
Router.run(routes, Router.HistoryLocation, (Handler, routerState) => { // note "routerState" here
21-
React.render(
21+
ReactDOM.render(
2222
<Provider store={store}>
23-
{() => <Handler routerState={routerState} />} // note "routerState" here
23+
{/* note "routerState" here */}
24+
<Handler routerState={routerState} />
2425
</Provider>,
2526
document.getElementById('root')
2627
);
@@ -41,13 +42,13 @@ You can also upgrade to React Router 1.0 which shouldn’t have this problem. (L
4142

4243
### My views aren’t updating when something changes outside of Redux
4344

44-
If your views depend on global state or [React “context”](www.youtube.com/watch?v=H7vlH-wntD4), you might find that views decorated with `connect()` will fail to update.
45+
If your views depend on global state or [React “context”](http://facebook.github.io/react/docs/context.html), you might find that views decorated with `connect()` will fail to update.
4546

4647
>This is because `connect()` implements [shouldComponentUpdate](https://facebook.github.io/react/docs/component-specs.html#updating-shouldcomponentupdate) by default, assuming that your component will produce the same results given the same props and state. This is a similar concept to React’s [PureRenderMixin](https://facebook.github.io/react/docs/pure-render-mixin.html).
4748
4849
The _best_ solution to this is to make sure that your components are pure and pass any external state to them via props. This will ensure that your views do not re-render unless they actually need to re-render and will greatly speed up your application.
4950

50-
If that's not practical for whatever reason (for example, if you’re using a library that depends heavily on React context), you may pass the `pure: false` option to `connect()`:
51+
If thats not practical for whatever reason (for example, if you’re using a library that depends heavily on React context), you may pass the `pure: false` option to `connect()`:
5152

5253
```
5354
function mapStateToProps(state) {
@@ -67,10 +68,8 @@ If you have context issues,
6768

6869
1. [Make sure you don’t have a duplicate instance of React](https://medium.com/@dan_abramov/two-weird-tricks-that-fix-react-7cf9bbdef375) on the page.
6970
2. Make sure you didn’t forget to wrap your root component in [`<Provider>`](#provider-store).
70-
3. If you use React Router, something like `<Provider>{() => router}</Provider>` won’t work. Due to the way context works in React 0.13, it’s important that the `<Provider>` children are *created* inside that function. Just referencing an outside variable doesn’t do the trick. Instead of `<Provider>{() => router}</Provider>`, write `<Provider>{() => createRouter()}</Provider>` where `createRouter()` is a function that actually *creates* (and returns) the router.
71+
3. Make sure you’re running the latest versions of React and React Redux.
7172

7273
### Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. This usually means that you’re trying to add a ref to a component that doesn’t have an owner
7374

7475
If you’re using React for web, this usually means you have a [duplicate React](https://medium.com/@dan_abramov/two-weird-tricks-that-fix-react-7cf9bbdef375). Follow the linked instructions to fix this.
75-
76-
If you’re using React Native, make sure you’re importing `react-redux/native` both for `<Provider>` and any `connect()` call. Importing from `react-redux` will not work on React Native.

0 commit comments

Comments
 (0)