diff --git a/_posts/2015-12-16-ismounted-antipattern.md b/_posts/2015-12-16-ismounted-antipattern.md index 8f7d2da81..a819b04f0 100644 --- a/_posts/2015-12-16-ismounted-antipattern.md +++ b/_posts/2015-12-16-ismounted-antipattern.md @@ -75,6 +75,5 @@ const makeCancelable = (promise) => { }; }; ``` -As an added bonus for getting your code cleaned up early, getting rid of `isMounted()` makes it one step easier for you to upgrade to ES6 classes, where using `isMounted()` is already prohibited. Happy coding! -* _Update 2017-05-12: altered `#makeCancelable` implementation so rejected promises won't go uncaught._ +As an added bonus for getting your code cleaned up early, getting rid of `isMounted()` makes it one step easier for you to upgrade to ES6 classes, where using `isMounted()` is already prohibited. Happy coding! diff --git a/docs/addons-animation.md b/docs/addons-animation.md index 557897de5..840ede726 100644 --- a/docs/addons-animation.md +++ b/docs/addons-animation.md @@ -10,8 +10,9 @@ redirect_from: - "docs/animation-zh-CN.html" --- ->Note: -> `ReactTransitionGroup` and `ReactCSSTransitionGroup` are both deprecated as of React v15.5.0. The recommendation is to use `TransitionGroup` and `CSSTransitionGroup` from ['react-transition-group'](https://github.com/reactjs/react-transition-group) instead. +> Note: +> +> `ReactTransitionGroup` and `ReactCSSTransitionGroup` are both deprecated as of React v15.5.0. The recommendation is to use `TransitionGroup` and `CSSTransitionGroup` from [`react-transition-group`](https://github.com/reactjs/react-transition-group) instead. The [`ReactTransitionGroup`](#low-level-api-reacttransitiongroup) add-on component is a low-level API for animation, and [`ReactCSSTransitionGroup`](#high-level-api-reactcsstransitiongroup) is an add-on component for easily implementing basic CSS animations and transitions. diff --git a/docs/addons-pure-render-mixin.md b/docs/addons-pure-render-mixin.md index 02b213bdc..cb71ec52a 100644 --- a/docs/addons-pure-render-mixin.md +++ b/docs/addons-pure-render-mixin.md @@ -7,6 +7,7 @@ category: Add-Ons --- > Note: +> > `PureRenderMixin` is a legacy add-on. Use [`React.PureComponent`](/react/docs/react-api.html#react.purecomponent) instead. **Importing** diff --git a/docs/addons-shallow-compare.md b/docs/addons-shallow-compare.md index 55e7f45d3..79de40d48 100644 --- a/docs/addons-shallow-compare.md +++ b/docs/addons-shallow-compare.md @@ -7,6 +7,7 @@ category: Reference --- > Note: +> > `shallowCompare` is a legacy add-on. Use [`React.PureComponent`](/react/docs/react-api.html#react.purecomponent) instead. **Importing** diff --git a/docs/addons-shallow-renderer.md b/docs/addons-shallow-renderer.md index fd1f96212..c69ea5c48 100644 --- a/docs/addons-shallow-renderer.md +++ b/docs/addons-shallow-renderer.md @@ -9,23 +9,15 @@ category: Reference **Importing** ```javascript -import ReactShallowRenderer from 'react-test-renderer/shallow'; // ES6 -var ReactShallowRenderer = require('react-test-renderer/shallow'); // ES5 with npm +import ShallowRenderer from 'react-test-renderer/shallow'; // ES6 +var ShallowRenderer = require('react-test-renderer/shallow'); // ES5 with npm ``` -### Shallow Rendering + +## Overview When writing unit tests for React, shallow rendering can be helpful. Shallow rendering lets you render a component "one level deep" and assert facts about what its render method returns, without worrying about the behavior of child components, which are not instantiated or rendered. This does not require a DOM. - - [`shallowRenderer.render()`](#shallowrenderer.render) - - [`shallowRenderer.getRenderOutput()`](#shallowrenderer.getrenderoutput) - -You can think of the shallowRenderer as a "place" to render the component you're testing, and from which you can extract the component's output. - -[`shallowRenderer.render()`](#shallowrenderer.render) is similar to [`ReactDOM.render()`](/react/docs/react-dom.html#render) but it doesn't require DOM and only renders a single level deep. This means you can test components isolated from how their children are implemented. - -After `shallowRenderer.render()` has been called, you can use [`shallowRenderer.getRenderOutput()`](#shallowrenderer.getrenderoutput) to get the shallowly rendered output. - -You can then begin to assert facts about the output. For example, if you have the following component: +For example, if you have the following component: ```javascript function MyComponent() { @@ -41,10 +33,12 @@ function MyComponent() { Then you can assert: ```javascript -const ReactShallowRenderer = require('react-test-renderer/shallow'); -const shallowRenderer = new ReactShallowRenderer(); -shallowRenderer.render(); -const result = shallowRenderer.getRenderOutput(); +import ShallowRenderer from 'react-test-renderer/shallow'; + +// in your test: +const renderer = new ShallowRenderer(); +renderer.render(); +const result = renderer.getRenderOutput(); expect(result.type).toBe('div'); expect(result.props.children).toEqual([ @@ -55,5 +49,20 @@ expect(result.props.children).toEqual([ Shallow testing currently has some limitations, namely not supporting refs. -We also recommend checking out Enzyme's [Shallow Rendering API](http://airbnb.io/enzyme/docs/api/shallow.html). It provides a nicer higher-level API over the same functionality. +> Note: +> +> We also recommend checking out Enzyme's [Shallow Rendering API](http://airbnb.io/enzyme/docs/api/shallow.html). It provides a nicer higher-level API over the same functionality. +## Reference + +### `shallowRenderer.render()` + +You can think of the shallowRenderer as a "place" to render the component you're testing, and from which you can extract the component's output. + +`shallowRenderer.render()` is similar to [`ReactDOM.render()`](/react/docs/react-dom.html#render) but it doesn't require DOM and only renders a single level deep. This means you can test components isolated from how their children are implemented. + +### `shallowRenderer.getRenderOutput()` + +After `shallowRenderer.render()` has been called, you can use `shallowRenderer.getRenderOutput()` to get the shallowly rendered output. + +You can then begin to assert facts about the output. diff --git a/docs/addons-test-utils.md b/docs/addons-test-utils.md index 6e9541037..bf689464f 100644 --- a/docs/addons-test-utils.md +++ b/docs/addons-test-utils.md @@ -41,8 +41,14 @@ var ReactTestUtils = require('react-dom/test-utils'); // ES5 with npm ## Shallow Rendering +When writing unit tests for React, shallow rendering can be helpful. Shallow rendering lets you render a component "one level deep" and assert facts about what its render method returns, without worrying about the behavior of child components, which are not instantiated or rendered. This does not require a DOM. + > Note: -> The shallow renderer has moved to `react-test-renderer/shallow`. [Please see the updated documentation.](/react/docs/shallow-renderer.html) +> +> The shallow renderer has moved to `react-test-renderer/shallow`.
+> [Learn more about shallow rendering on its reference page.](/react/docs/shallow-renderer.html) + +## Other Utilities ### `Simulate` diff --git a/docs/addons-two-way-binding-helpers.md b/docs/addons-two-way-binding-helpers.md index 1d08193c0..d41a5a49b 100644 --- a/docs/addons-two-way-binding-helpers.md +++ b/docs/addons-two-way-binding-helpers.md @@ -7,6 +7,7 @@ category: Add-Ons --- > Note: +> > `LinkedStateMixin` is deprecated as of React v15. The recommendation is to explicitly set the value and change handler, instead of using `LinkedStateMixin`. **Importing** diff --git a/docs/addons-update.md b/docs/addons-update.md index b85ea8086..51b1295b3 100644 --- a/docs/addons-update.md +++ b/docs/addons-update.md @@ -7,7 +7,8 @@ category: Add-Ons --- > Note: -> `update` is a legacy add-on. Use [kolodny/immutability-helper](https://github.com/kolodny/immutability-helper) instead. +> +> `update` is a legacy add-on. Use [`immutability-helper`](https://github.com/kolodny/immutability-helper) instead. **Importing** diff --git a/docs/lifting-state-up.md b/docs/lifting-state-up.md index 643240cfe..56ab0feb2 100644 --- a/docs/lifting-state-up.md +++ b/docs/lifting-state-up.md @@ -196,7 +196,9 @@ Now, when the `TemperatureInput` wants to update its temperature, it calls `this this.props.onTemperatureChange(e.target.value); ``` -> Note that there is no special meaning to either `temperature` or `onTemperatureChange` prop names in custom components. We could have called them anything else, like name them `value` and `onChange` which is a common convention. +>Note: +> +>There is no special meaning to either `temperature` or `onTemperatureChange` prop names in custom components. We could have called them anything else, like name them `value` and `onChange` which is a common convention. The `onTemperatureChange` prop will be provided together with the `temperature` prop by the parent `Calculator` component. It will handle the change by modifying its own local state, thus re-rendering both inputs with the new values. We will look at the new `Calculator` implementation very soon.