所以我一直在研究一个可重用的图标元素,我可以在任何类中调用它,只传递一个<Icon name="chat" />
包含图标特定颜色的字符串..这个错误是我提出的上一个问题的结果..你可以找到链接以下
icon.ts 文件
const iconsList = {
heart: '',
star: '',
like: '',
dislike: '',
flash: '',
marker: '',
filter: '',
user: '',
circle: '',
hashtag: '',
calendar: '',
chevronLeft: '',
optionsV: '',
optionsH: '',
chat: '',
explore: ''
};
interface Props{
name: keyof typeof iconsList;
}
const Icon = ({name }: Props) => {
let icon = iconsList[name];
icon = icon.substr(3);
icon = String.fromCharCode(parseInt(icon, 16));
return icon;
};
export default Icon;
配置文件.tsx
import React from 'react';
import styles from '../assets/styles';
import {
ScrollView,
View,
Text,
ImageBackground,
TouchableOpacity
} from 'react-native';
import Icon from '../components/Icon';
const Profile = () => {
return (
<TouchableOpacity>
<Text style={styles.topIconLeft}>
<Icon name="chevronLeft" />
</Text>
</TouchableOpacity>
);
}
这一行<Icon name="chevronLeft" />
抱怨错误“JSX 元素类型‘字符串’不是 JSX 元素的构造函数。ts(2605)