首页 > 解决方案 > Multiple Instances in React native functional components?

问题描述

I am using the code of my file

const first = () =>{
return(
<View>
</View>)
}

I want to create multiple instances of the the first component so that i can use it as tabs, and i want to save instance of the component.i want that i can create new instance and if i want to use old instance then i get the same data as i left the screen before creating new instance. Can anybody help to create multiple instances of the react functional component. And how can i recover of view instance when i want to see it again.

标签: react-nativeinstancereact-functional-componentmulti-instance-deployment

解决方案


您可以使用附加组件实例React.useRef。但是,您必须注意,firstInstance在重新渲染中总是相同的。

function CompThatUsesInstances() {
   const firstInstance = React.useRef(<First />);
  
   return (
     <View>
       {firstInstance.current}
     </View>
   )
}

推荐阅读