<Select defaultValue="lucy" style={{ width: 120 }} onChange={handleChange}>
<Option value="jack">Jack</Option>
<Option value="lucy">Lucy</Option>
<Option value="disabled" disabled>
Disabled
</Option>
<Option value="Yiminghe">yiminghe</Option>
</Select>
<Radio.Group onChange={this.onChange} value={this.state.value}>
<Radio style={radioStyle} value={1}>
Option A
</Radio>
<Radio style={radioStyle} value={2}>
Option B
</Radio>
</Radio.Group>
// B 组件
function B () {
return <div>
B
</div>
}
class A extends React.Component {
render () {
// 在这里判断 type 是不是 B
// 2020-03-28 新增, 有时候不能通过 type 直接判断时
// 可以通过 children.type.name === 'B' 来判断
console.log(this.props.children.type === B)
return <div>
{this.props.children}
</div>
}
}
function App () {
return <div>
<A>
<B />
</A>
</div>
}
class A extends React.Component {
render () {
console.log(this.props.children.map(ele => {
return ele.type === B
}))
return <div>
{this.props.children}
</div>
}
}
class B extends React.Component {
render () {
return <div>
B
</div>
}
}