簡體   English   中英

如何在其他組件內動態傳遞多個組件反應本機

[英]How to pass multiple components dynamically inside other component react native

照片

我認為我的問題很簡單,但是我正在學習 RN 並且卡住了。 我想在 KennelScreen 組件中動態傳遞 Header、PhotoCarousel、UserDetails 組件,因為現在我只是用 JS 的方式做的。 有沒有其他方法可以做到?

謝謝!

取決於您要存檔的內容。 您可以通過動態創建它們

const KennelScreen = () => {
  return (
    <SafeAreaView>
      <ScrollView>
        {React.Children.map(this.props.children, (child) =>
          React.cloneElement(child)
        )}
      </ScrollView>
    </SafeAreaView>
  );
};

然后你可以在你的父屏幕中使用它

<KennelScreen>
 <Header />
....
</KennelScreen>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM