2015-01-30 01:10:49 +00:00
|
|
|
/**
|
2016-07-05 13:34:00 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
2015-01-30 01:10:49 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +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-07-06 22:00:17 +00:00
|
|
|
*
|
2015-01-30 01:10:49 +00:00
|
|
|
* @providesModule StaticContainer.react
|
2015-07-06 22:00:17 +00:00
|
|
|
* @flow
|
2015-01-30 01:10:49 +00:00
|
|
|
*/
|
2016-07-05 13:34:00 +00:00
|
|
|
'use strict';
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2016-10-15 01:50:15 +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.
|
|
|
|
*
|
2016-10-15 01:50:15 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
2017-08-18 01:36:54 +00:00
|
|
|
class StaticContainer extends React.Component<Object> {
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2015-07-06 22:00:17 +00:00
|
|
|
shouldComponentUpdate(nextProps: Object): boolean {
|
|
|
|
return !!nextProps.shouldUpdate;
|
|
|
|
}
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2015-07-06 22:00:17 +00:00
|
|
|
render() {
|
2016-10-15 01:50:15 +00:00
|
|
|
const child = this.props.children;
|
|
|
|
return (child === null || child === false)
|
|
|
|
? null
|
|
|
|
: React.Children.only(child);
|
2015-01-30 01:10:49 +00:00
|
|
|
}
|
|
|
|
|
2015-07-06 22:00:17 +00:00
|
|
|
}
|
2015-01-30 01:10:49 +00:00
|
|
|
|
|
|
|
module.exports = StaticContainer;
|