Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80517 views
1
/**
2
* Copyright 2013-2015, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @providesModule ReactComponentWithPureRenderMixin
10
*/
11
12
'use strict';
13
14
var shallowEqual = require("./shallowEqual");
15
16
/**
17
* If your React component's render function is "pure", e.g. it will render the
18
* same result given the same props and state, provide this Mixin for a
19
* considerable performance boost.
20
*
21
* Most React components have pure render functions.
22
*
23
* Example:
24
*
25
* var ReactComponentWithPureRenderMixin =
26
* require('ReactComponentWithPureRenderMixin');
27
* React.createClass({
28
* mixins: [ReactComponentWithPureRenderMixin],
29
*
30
* render: function() {
31
* return <div className={this.props.className}>foo</div>;
32
* }
33
* });
34
*
35
* Note: This only checks shallow equality for props and state. If these contain
36
* complex data structures this mixin may have false-negatives for deeper
37
* differences. Only mixin to components which have simple props and state, or
38
* use `forceUpdate()` when you know deep data structures have changed.
39
*/
40
var ReactComponentWithPureRenderMixin = {
41
shouldComponentUpdate: function(nextProps, nextState) {
42
return !shallowEqual(this.props, nextProps) ||
43
!shallowEqual(this.state, nextState);
44
}
45
};
46
47
module.exports = ReactComponentWithPureRenderMixin;
48
49