Reactjs React-将组件作为参数传递给另一个组件

Reactjs React-将组件作为参数传递给另一个组件,reactjs,react-native,Reactjs,React Native,我想有一个标题,可以自定义视图的基础上,其屏幕调用。所以我需要将组件作为参数传递给我的头组件。但它似乎不起作用 这是我的自定义组件 ... const ComponentRight = () => { return ( <Right> <Button transparent onPress= {() => { {enablePinned ?

我想有一个标题,可以自定义视图的基础上,其屏幕调用。所以我需要将组件作为参数传递给我的头组件。但它似乎不起作用

这是我的自定义组件

...    
const ComponentRight = () => {
      return (
        <Right>
            <Button transparent onPress= {() => {
                {enablePinned ?
                  addChatPinned(chatSelected) :
                  removeChatPinned(chatSelected)
                }
            }}>
              {enablePinned ?
                <Icon type= 'MaterialCommunityIcons' name= 'pin'/> :
                <Icon type= 'MaterialCommunityIcons' name= 'pin-off'/>
              }
            </Button>
            <Button 
              transparent
              onPress= {() => deleteChatList(chatSelected)}>
              <Icon type= 'FontAwesome5' name= 'trash' style= {{fontSize: 20}}/>
            </Button>
            <Button transparent>
              <Icon type= 'MaterialIcons' name= 'archive' style= {{fontSize: 25}}/>
            </Button>
          </Right>
      )
    }

    return (
      <Container>
        {showAction ?
          <SelectHeader
            onBack= {resetChatSelected()}
            itemCount= {chatSelected.length}
            componentRight= {ComponentRight}/> // passing my component as argument
...
。。。
常量组件右=()=>{
返回(
{
{启用锁定?
addChatPinned(chatSelected):
removeChatPinned(已选定)
}
}}>
{启用锁定?
:
}
删除聊天列表(聊天室已选择)}>
)
}
返回(
{表演?
//将我的组件作为参数传递
...
这是我的标题部分

const SelectHeader = ({onBack, itemCount, componentRight}) => {
    return (
        <Header style= {appStyles.headerBackgroundColor}>
            <Left style= {{flexDirection: 'row'}}>
              <Button 
                transparent 
                style= {{marginRight: 30}}
                onPress= {() => {onBack}}>
                <Icon type='Ionicons' name= 'md-arrow-back' style= {{fontSize: 25}} color= 'white'/>
              </Button>
              <Title style= {appStyles.appTitle, {alignSelf: 'center'}}>{itemCount}</Title>
            </Left>
            <Body/>
            {componentRight}
          </Header> 
    )
}

export default SelectHeader
const SelectHeader=({onBack,itemCount,componentRight})=>{
返回(
{onBack}}>
{itemCount}
{componentRight}
)
}
导出默认SelectHeader

有人知道如何做到这一点吗?谢谢你可以传递这样一个组件:

<MyComponent
  propComponent={<MyPropComponent />}
/>


如果需要,您甚至可以将道具传递给该组件。

您可以这样传递组件:

<MyComponent
  propComponent={<MyPropComponent />}
/>


如果需要,您甚至可以将道具传递给该组件。

这称为高阶组件[1],只需将该组件作为道具传递并在渲染方法中使用即可


  • 这称为高阶组件[1],只需将组件作为道具传递,并在渲染方法中使用它