javascript - 条件 jsx 元素 React native
问题描述
我尝试在加载 webview 时显示文本,但 ActivityIndicator 没有消失。
我试图创建一个带有布尔变量的钩子,该变量在加载 webview 时会发生变化,然后它应该显示文本“你好,我是你的猫!” 在第一个条件。
import React,{useState} from 'react';
import { Text, StyleSheet, View, ActivityIndicator } from 'react-native';
import { WebView } from 'react-native-webview';
const Cat = () => {
return (
<Cat />
);
}
const Cafe = () => {
const [ok, setOk] = useState(false);
return (
ok ?
<Text>Hello, I am your cat!</Text>
:
<View style={styles.container}>
<View style={{height: 0, width: 0}}>
<WebView
source={{uri: "https://www.google.com/"}}
onLoad={() => {
setOk(true)
console.log(ok);
}}
/>
</View>
<ActivityIndicator size="large" color="#E60081"/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#000',
alignItems: 'center',
justifyContent: 'center',
},
});
export default Cafe;
解决方案
您正在传递对您的onLoad
函数的引用。试试下面的代码。
<WebView
source={{uri: "https://www.google.com/"}}
onLoad={setOk(true)}
/>
推荐阅读
- html - 为什么粘性不起作用?
- android - 文具对象领域的大约查询时间是多少?
- amazon-web-services - EC2 EMR 未执行问题 spark-submit not found
- c# - ASP.NET MVC 重定向最佳实践
- node.js - Passport SerializeUser 被多次调用
- c# - 你如何在xaml的listview中拉伸图像?
- r - data.table 与 dplyr 不同
- sql - 有 CASE 语句时,ROLLUP 行无法正确求和
- mqtt - Mosquitto-Auth 插件没有用客户端 ID 替换 ACL 中的 %c
- mysql - 为什么这个 CASE 运算符不工作?