RN版本:0.69
当我在使用typescript编写ReactNative组件时, 使用Platform.select编写的组件在调用的时候报"JSX 元素类型“Test”不具有任何构造签名或调用签名"错误。
import React from 'react';
import { Platform, Text } from 'react-native';
const IosComp = ({ text = 'ios' }: { text: string }) => {
return <Text>{text}Text>;
};
const AndroidComp = ({ text = 'android' }: { text: string }) => {
return <Text>{text}Text>;
};
const Test = Platform.select({
ios: IosComp,
android: AndroidComp,
});
export default Test;
在调用的时候报错
我不知道是我组件写错了还是我typescript环境配错了,怎么在调用Test组件的时候就会报错呢,我很是不解!
希望能够得到有用的帮助,十分感谢!
作为组件使用时,要执行Platform.select({...})()
const Test = Platform.select({
ios: IosComp,
android: AndroidComp,
})();