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.

Rover
  • 661
  • 2
  • 18
  • 39

1 Answers1

0

You could attach your instance of the component using React.useRef. But, you have to note, that the firstInstance is always the same across re-renders.

function CompThatUsesInstances() {
   const firstInstance = React.useRef(<First />);
  
   return (
     <View>
       {firstInstance.current}
     </View>
   )
}
Prateek Thapa
  • 4,829
  • 1
  • 9
  • 23
  • suppose i want to create 10 screens from the same component. And i want to save instance . So that i can call 1 instance, 2 instance and get same data screen that i left. Before move to next one. How can i do that – Rover Jan 01 '21 at 12:40
  • How can make it dynamic. Like save instance in a file, And create 100 Instance and then can view any instance. @Prateek – Rover Jan 01 '21 at 13:41