react-native/Libraries/Components/StaticContainer.react.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

2015-01-30 01:10:49 +00:00
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
2015-01-30 01:10:49 +00:00
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
2015-01-30 01:10:49 +00:00
* @providesModule StaticContainer.react
* @flow
2015-01-30 01:10:49 +00:00
*/
'use strict';
2015-01-30 01:10:49 +00:00
const React = require('React');
2015-01-30 01:10:49 +00:00
/**
* Renders static content efficiently by allowing React to short-circuit the
* reconciliation process. This component should be used when you know that a
* subtree of components will never need to be updated.
*
* const someValue = ...; // We know for certain this value will never change.
2015-01-30 01:10:49 +00:00
* return (
* <StaticContainer>
* <MyComponent value={someValue} />
* </StaticContainer>
* );
*
* Typically, you will not need to use this component and should opt for normal
* React reconciliation.
*/
class StaticContainer extends React.Component {
2015-01-30 01:10:49 +00:00
shouldComponentUpdate(nextProps: Object): boolean {
return !!nextProps.shouldUpdate;
}
2015-01-30 01:10:49 +00:00
render() {
const child = this.props.children;
return (child === null || child === false)
? null
: React.Children.only(child);
2015-01-30 01:10:49 +00:00
}
}
2015-01-30 01:10:49 +00:00
module.exports = StaticContainer;