typescript - 如何根据平台导入模块
问题描述
我想根据平台导入一个模块。
例如:
import MapViewIOS from 'react-native-map-clustering'
import MapViewAndroid from 'react-native-maps'
const MapView = Platform.select({
ios: MapViewIOS,
android: MapViewAndroid,
})
错误:
JSX 元素类型“MapView”没有任何构造或调用 signatures.ts(2604)
解决方案
在 react-native 中,您应该按平台分隔文件。例如,使用MapView.ios.js
和MapView.android.js
名称创建两个文件,以便为平台和任何需要使用 MapView 的地方导出特定组件,像这样导入它们import MapView from "./MapView"
推荐阅读
- google-apps-script - 嵌套 IF 语句的脚本替代 Google 表格,忽略文本单元格
- arrays - C索引到数组的双指针会导致崩溃
- git - 第一次使用 Git 用户,推送到远程存储库需要很长时间
- apache-spark-sql - 在 pyspark SQL 中将字符串日期转换为日期格式
- c# - 如何使用 ASP.NET Core MVC 模型验证属性指定验证消息是否显示在摘要中、表单中或两者中
- mapbox - Mapbox 在多边形上显示平铺边框,样式为线条
- vb.net - userControl 内的文本框 TextChanged 问题(C# 代码到 vb.net)
- bash - Linux - 查找每个目录中每组文件的最大修改日期
- python - 如何修复无法将集合与 SQL Alchemy 中的对象进行比较?
- symfony - Raspbian / Mercure - 绑定:权限被拒绝