0

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.

4

1 回答 1

0

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

function CompThatUsesInstances() {
   const firstInstance = React.useRef(<First />);
  
   return (
     <View>
       {firstInstance.current}
     </View>
   )
}
于 2021-01-01T12:32:38.823 回答