RN: Change `onlyChild => React.Children.only`

Reviewed By: sebmarkbage

Differential Revision: D4025440

fbshipit-source-id: efbcb44dcc89a6059688cf5a00cf28ada8a6a4c4
This commit is contained in:
Tim Yung 2016-10-14 18:50:15 -07:00 committed by Facebook Github Bot
parent 331c13d4dc
commit c4fc13b997
4 changed files with 9 additions and 12 deletions

View File

@ -11,16 +11,14 @@
*/
'use strict';
var React = require('React');
var onlyChild = require('react/lib/onlyChild');
const React = require('React');
/**
* 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.
*
* var someValue = ...; // We know for certain this value will never change.
* const someValue = ...; // We know for certain this value will never change.
* return (
* <StaticContainer>
* <MyComponent value={someValue} />
@ -37,8 +35,10 @@ class StaticContainer extends React.Component {
}
render() {
var child = this.props.children;
return (child === null || child === false) ? null : onlyChild(child);
const child = this.props.children;
return (child === null || child === false)
? null
: React.Children.only(child);
}
}

View File

@ -27,7 +27,6 @@ var ensureComponentIsNative = require('ensureComponentIsNative');
var ensurePositiveDelayProps = require('ensurePositiveDelayProps');
var keyOf = require('fbjs/lib/keyOf');
var merge = require('merge');
var onlyChild = require('react/lib/onlyChild');
type Event = Object;
@ -243,7 +242,7 @@ var TouchableHighlight = React.createClass({
onResponderTerminate={this.touchableHandleResponderTerminate}
testID={this.props.testID}>
{React.cloneElement(
onlyChild(this.props.children),
React.Children.only(this.props.children),
{
ref: CHILD_REF,
}

View File

@ -19,7 +19,6 @@ var TouchableWithoutFeedback = require('TouchableWithoutFeedback');
var UIManager = require('UIManager');
var ensurePositiveDelayProps = require('ensurePositiveDelayProps');
var onlyChild = require('react/lib/onlyChild');
var processColor = require('processColor');
var requireNativeComponent = require('requireNativeComponent');
@ -222,7 +221,7 @@ var TouchableNativeFeedback = React.createClass({
},
render: function() {
const child = onlyChild(this.props.children);
const child = React.Children.only(this.props.children);
let children = child.props.children;
if (Touchable.TOUCH_TARGET_DEBUG && child.type.displayName === 'View') {
if (!Array.isArray(children)) {

View File

@ -18,7 +18,6 @@ const Touchable = require('Touchable');
const View = require('View');
const ensurePositiveDelayProps = require('ensurePositiveDelayProps');
const onlyChild = require('react/lib/onlyChild');
const warning = require('fbjs/lib/warning');
type Event = Object;
@ -150,7 +149,7 @@ const TouchableWithoutFeedback = React.createClass({
render: function(): React.Element<any> {
// Note(avik): remove dynamic typecast once Flow has been upgraded
const child = onlyChild(this.props.children);
const child = React.Children.only(this.props.children);
let children = child.props.children;
warning(
!child.type || child.type.displayName !== 'Text',