Is there a Ionicons: Icon props? Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Is there a Ionicons: Icon props? without wasting too much if your time.

The question is published on by Tutorial Guruji team.

So I am writing a functional component right, I written a props.
So I wanted it to able to auto suggest name attributes. Something like this

import { Ionicons } from "@expo/vector-icons";

export interface ownWrittenProps {
  leftIcon?: ????????;
}

so when people start typing <FunctionalComponent leftIcon=” it can suggest the acceptable icon names from Ionicons the reason I want to use it because it pack into the ios/apk package anyway. What should I put in ???????? so that it can suggest the name?

Another question, if I have a textbox in my ChildComponent how do I retrieve the text/value from parent?

Answer

@expo-vector-icons exposes a glyphMap for each icon type. You can use this to generate the name suggestions.

import { Ionicons } from '@expo/vector-icons';

export interface ownWrittenProps {
  leftIcon?: keyof typeof Ionicons.glyphMap;
}

This will create a type from the map, then make sure that only keys of that type can be used when setting leftIcon.

We are here to answer your question about Is there a Ionicons: Icon props? - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji