Reactjs 如何在React中将一个组件传递给另一个组件?

Reactjs 如何在React中将一个组件传递给另一个组件?,reactjs,mobx,Reactjs,Mobx,我想写一个如下的选项卡组件,当我点击tab1来显示test的内容时没关系,但是当我定义一个类组件,如test2时,它似乎是错误的。错误是“Uncaught TypeError:无法将类作为函数调用”。非常感谢 // use of component const tabs = [ {tabName: 'tab1', content: () => <Tab.Pane component={test} /> }, {tabName: 'tab2', content:

我想写一个如下的选项卡组件,当我点击tab1来显示test的内容时没关系,但是当我定义一个类组件,如test2时,它似乎是错误的。错误是“Uncaught TypeError:无法将类作为函数调用”。非常感谢

// use of component
const tabs = [
    {tabName: 'tab1', content: () => <Tab.Pane component={test} /> },
    {tabName: 'tab2', content: () => <Tab.Pane component={test2} /> }
];

const test = () => {
    return (<HGroup>tetetetetetet</HGroup>)
};
class test2 extends Component {
    render() {
        return(<HGroup>123213</HGroup>)
    }
}

@observer
export default class EditLabels extends Component {
    render() {
      return (<Tab panes={tabs} />)
    }
}


// component 
@observer
class Tab extends Component {

@observable activeIndex = 0;

static Pane = ({children, component}) => {

    console.log(typeof component);
    return (
        <VGroup>
            {children && <HGroup>{children}</HGroup>}
            {component && component.call(this)}
        </VGroup>

    )
};

render() {
    const { panes } = this.props;
    return (
        <VGroup>
            <HGroup>{ panes.map((item, index) => {
                return (<HGroup key={index}
                                onClick={() => this.activeIndex = index}
                                style={this.activeIndex === index && {color: 'red'}}>{item.tabName}</HGroup>)
            })}
            </HGroup>

            {panes[this.activeIndex].content()}

        </VGroup>
    )
}
}
//组件的使用
常量选项卡=[
{tabName:'tab1',内容:()=>},
{tabName:'tab2',内容:()=>}
];
常数测试=()=>{
返回(四重奏)
};
类test2扩展了组件{
render(){
返回(123213)
}
}
@观察者
导出默认类EditLabels扩展组件{
render(){
返回()
}
}
//组成部分
@观察者
类选项卡扩展组件{
@可观测活动指数=0;
静态窗格=({children,component})=>{
控制台日志(组件类型);
返回(
{children&&{children}
{component&&component.call(this)}
)
};
render(){
const{panes}=this.props;
返回(
{panes.map((项目,索引)=>{
返回(this.activeIndex=index}
style={this.activeIndex===index&&{color:'red'}}>{item.tabName})
})}
{窗格[this.activeIndex].content()}
)
}
}

返回JSX不需要函数。我通常做
constmycop=似乎,因为
test2
是一个类,所以窗格中的
{component&&component.call(this)}
是导致它失败的原因。我们无法对类调用
.call()
,因此会引发TypeError异常。尝试删除
.call()
,只需保留该行
{component}