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

45 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2015-01-30 01:10:49 +00:00
/**
* Copyright (c) 2015-present, Facebook, Inc.
2015-01-30 01:10:49 +00:00
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
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<Object> {
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;