react-native - 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.useRef
。但是,您必须注意,firstInstance
在重新渲染中总是相同的。
function CompThatUsesInstances() {
const firstInstance = React.useRef(<First />);
return (
<View>
{firstInstance.current}
</View>
)
}
推荐阅读
- java - 如何使用 appium java 客户端 6.1.0 自动化 Android 手机底部的 Home、back、up、down、Menu 按钮?
- gruntjs - 如何在 grunt-durandal 中排除一个文件夹
- java - 最终列表或数组不会存储值
- selenium - Go-selenium:无法建立连接,因为目标机器主动拒绝它
- algorithm - CPC 广告优化算法可提高广告系列的效果
- unit-testing - 如何使用 testng/junit 测试 Class.forName()?
- php - 您可以在 Stripe 中屏蔽卡号吗?
- vimeo - vimeo php api 添加视频标签
- image - 如何从以下没有文字的图像中提取 9 张图像?
- javascript - 如何将异步函数应用于reduce操作的每个项目?