Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Yes, a TypeScript definition for icon names can be provided in MaterialCommunityIcons for React Native. The definition can be created using the IconProps interface for the component and specifying the possible values for the name prop using a union type. Here's an example:

import { IconProps } from 'react-native-vector-icons/MaterialCommunityIcons';

type MaterialCommunityIconName =
  | 'account'
  | 'bell'
  | 'camera'
  | 'car'
  | 'clock'
  | 'email'
  // add more names here

interface MaterialCommunityIconProps extends IconProps {
  name: MaterialCommunityIconName;
}

// usage:
import MCIcon from 'react-native-vector-icons/MaterialCommunityIcons';

const MyComponent = () => (
  <MCIcon name="account" size={30} color="red" />
);

This provides type safety for the name prop and ensures that only allowed icon names are used.