I'm trying to find out the type definitions for the icon name of expo/vector-icons , since I am intending to use it for a component props.
I am import expo/vector-icons like and and defining interface props like this, I tried type icon name as string.
import Icon from "@expo/vector-icons/FontAwesome"
interface Props {
icon: string
value: string
placeholder: string
onChangeText: (text: string) => void
secureTextEntry?: boolean
style: StyleProp<ViewStyle>
}
This is how I am using the prop.
<Icon name={icon} size={20} style={styles.icon} />
you have to change the type of your icon Props,
import { Ionicons } from '@expo/vector-icons';
and use glyphMap property from Ionicons, just like this
icon: keyof typeof Ionicons.glyphMap
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.