1 | /**
|
2 | * Copyright (c) 2013-present, Facebook, Inc.
|
3 | *
|
4 | * This source code is licensed under the MIT license found in the
|
5 | * LICENSE file in the root directory of this source tree.
|
6 | *
|
7 | */
|
8 |
|
9 | ;
|
10 |
|
11 | var shallowCompare = require('./shallowCompare');
|
12 |
|
13 | /**
|
14 | * If your React component's render function is "pure", e.g. it will render the
|
15 | * same result given the same props and state, provide this mixin for a
|
16 | * considerable performance boost.
|
17 | *
|
18 | * Most React components have pure render functions.
|
19 | *
|
20 | * Example:
|
21 | *
|
22 | * var ReactComponentWithPureRenderMixin =
|
23 | * require('ReactComponentWithPureRenderMixin');
|
24 | * React.createClass({
|
25 | * mixins: [ReactComponentWithPureRenderMixin],
|
26 | *
|
27 | * render: function() {
|
28 | * return <div className={this.props.className}>foo</div>;
|
29 | * }
|
30 | * });
|
31 | *
|
32 | * Note: This only checks shallow equality for props and state. If these contain
|
33 | * complex data structures this mixin may have false-negatives for deeper
|
34 | * differences. Only mixin to components which have simple props and state, or
|
35 | * use `forceUpdate()` when you know deep data structures have changed.
|
36 | *
|
37 | * See https://facebook.github.io/react/docs/pure-render-mixin.html
|
38 | */
|
39 | var ReactComponentWithPureRenderMixin = {
|
40 | shouldComponentUpdate: function (nextProps, nextState) {
|
41 | return shallowCompare(this, nextProps, nextState);
|
42 | }
|
43 | };
|
44 |
|
45 | module.exports = ReactComponentWithPureRenderMixin; |
\ | No newline at end of file |