我使用的反应原生0.61和我有两个文件。正如你可以看到下面我传递位置从FethcLocation.jsapp.js文件,并分配它作为一个位置对象。然后我把它传递给userMaps.js文件,并将其分配给经度和纬度值。
警告:失败的道具类型:无效道具区域。纬度
类型为字符串
提供给地图视图
,应为编号
。
获取位置。js
import React from 'react';
import {View} from 'react-native';
navigator.geolocation = require('@react-native-community/geolocation');
class FetchLocation extends React.Component {
componentDidMount() {
navigator.geolocation.getCurrentPosition(
position => {
this.props.setLocation(position);
},
error => {
console.log(error);
},
{enableHighAccuracy: false, timeout: 20000, maximumAge: 10000},
);
}
render() {
return <View></View>;
}
}
export default FetchLocation;
应用程序。js
import React from 'react';
import {Button} from 'react-native';
import FetchLocation from './components/FetchLocation';
import UserMaps from './components/UserMaps';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
location: {lat: '', lon: ''},
showTraffic: 'false',
};
}
assignLocation = props => {
this.setState({
location: {
lat: props.coords.latitude,
lon: props.coords.longitude,
},
});
};
manageTraffic = () => {
this.setState({
showTraffic: 'true',
});
console.log(this.state.showTraffic);
};
render() {
return (
<>
<Button title="Traffic" onPress={this.manageTraffic}></Button>
<FetchLocation setLocation={this.assignLocation} />
<UserMaps mapData={this.state} />
</>
);
}
}
export default App;
用户地图。js
import React from 'react';
import {View, StyleSheet} from 'react-native';
import MapView, {PROVIDER_GOOGLE} from 'react-native-maps';
const UserMaps = props => {
const {location, showTraffic} = props.mapData;
return (
<View style={styles.mapContainer}>
<MapView
provider={PROVIDER_GOOGLE}
showsUserLocation={true}
showsCompass={true}
showsBuildings={false}
showsTraffic={true}
showsIndoors={true}
style={styles.map}
region={{
latitude: location.lat,
longitude: location.lon,
latitudeDelta: 0.015,
longitudeDelta: 0.0121,
}}>
{/* <MapView.Marker coordinate={(location.lat + 2, location.lon + 2)} /> */}
</MapView>
</View>
);
};
const styles = StyleSheet.create({
mapContainer: {
width: '100%',
height: '100%',
},
map: {
height: '100%',
width: '100%',
},
});
export default UserMaps;
在变量之前添加Number()
,如下所示:
region={{
latitude: Number(location.lat),
longitude: Number(location.lon),
latitudeDelta: 0.015,
longitudeDelta: 0.0121,
}}>
或
<MapView.Marker coordinate={(
Number(location.lat) + 2,
Number(location.lon) + 2
)} />
我试图展示一个简单的例子。通过将图像路径作为道具发送到要渲染它的组件,来创建jpg图像。以下面的方式。 应用程序。js 图像显示。js 图像lider.js 我的文件夹结构是: 理想情况下,当我通过本地存储的图像路径时,图像应该被显示,但是我没有看到任何图像显示,而是一条警告消息,上面写着:“失败的道具类型:无效的道具‘源’提供给‘转发参考(图像)’”
我尝试动态渲染图像。但我得到了这个错误。动态获取图像源并进行渲染的解决方案是什么? 主要组成部分。js 卡片详情。js 我也尝试过其他方法,但没有成功。我在使用此方法时遇到此错误: 未知命名模块 主要组成部分。js 卡片详情。js
我有这个警告在我的项目:警告:失败的道具类型:无效的道具<代码>源代码提供给<代码>图像。我加载图像从sampleProducts.jsonRecommendend.js并通过它作为道具在Products.js,但图像不会加载,因为警告。 样本产品。json 建议。js 产品。js
这是什么错误??? 我得到了旧的工作代码,安装了新版本的libs,我看到了这个错误。但我不明白这是什么意思。 这是什么错误?我的代码怎么了?已安装路由器dom@^4.1。0:
我收到警告“警告:失败的道具类型:提供给的类型为
我得到这个错误: index.js:1375警告:失败的道具类型:提供给的道具无效。 我在我的应用程序中使用了一个外部组件,它是从github获得的,可以在后台渲染视频。这里是链接。https://github.com/samAbeywickrama/reactjs-videobg 它与proptypes有关,但由于它的遗留和react建议使用flo,所以我根本不使用类型检查。