Multiple Instances in React native functional components?

483 Views Asked by At

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.

1

There are 1 best solutions below

2
On

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>
   )
}