Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81152 views
1
/**
2
* Copyright 2013-2014, 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 shouldUpdateReactComponent
10
* @typechecks static-only
11
*/
12
13
"use strict";
14
15
/**
16
* Given a `prevElement` and `nextElement`, determines if the existing
17
* instance should be updated as opposed to being destroyed or replaced by a new
18
* instance. Both arguments are elements. This ensures that this logic can
19
* operate on stateless trees without any backing instance.
20
*
21
* @param {?object} prevElement
22
* @param {?object} nextElement
23
* @return {boolean} True if the existing instance should be updated.
24
* @protected
25
*/
26
function shouldUpdateReactComponent(prevElement, nextElement) {
27
if (prevElement && nextElement &&
28
prevElement.type === nextElement.type &&
29
prevElement.key === nextElement.key &&
30
prevElement._owner === nextElement._owner) {
31
return true;
32
}
33
return false;
34
}
35
36
module.exports = shouldUpdateReactComponent;
37
38