@@ -41,6 +41,7 @@ type FlagWithSomethingProp = Pick<
4141 | 'withCurrencyButton'
4242 | 'withCallingCodeButton'
4343 | 'withFlagButton'
44+ | 'placeholder'
4445> & { flagSize : number }
4546
4647const FlagText = ( props : TextProps & { children : ReactNode } ) => (
@@ -56,6 +57,7 @@ const FlagWithSomething = memo(
5657 withCallingCodeButton,
5758 withFlagButton,
5859 flagSize,
60+ placeholder,
5961 } : FlagWithSomethingProp ) => {
6062 const { translation, getCountryInfoAsync } = useContext ( )
6163 const [ state , setState ] = useState ( {
@@ -65,9 +67,11 @@ const FlagWithSomething = memo(
6567 } )
6668 const { countryName, currency, callingCode } = state
6769 useEffect ( ( ) => {
68- getCountryInfoAsync ( { countryCode, translation } )
69- . then ( setState )
70- . catch ( console . warn )
70+ if ( countryCode ) {
71+ getCountryInfoAsync ( { countryCode, translation } )
72+ . then ( setState )
73+ . catch ( console . warn )
74+ }
7175 } , [
7276 countryCode ,
7377 withCountryNameButton ,
@@ -77,9 +81,14 @@ const FlagWithSomething = memo(
7781
7882 return (
7983 < View style = { styles . flagWithSomethingContainer } >
80- < Flag
81- { ...{ withEmoji, countryCode, withFlagButton, flagSize : flagSize ! } }
82- />
84+ { countryCode ? (
85+ < Flag
86+ { ...{ withEmoji, countryCode, withFlagButton, flagSize : flagSize ! } }
87+ />
88+ ) : (
89+ < FlagText > { placeholder } </ FlagText >
90+ ) }
91+
8392 { withCountryNameButton && countryName ? (
8493 < FlagText > { countryName + ' ' } </ FlagText >
8594 ) : null }
@@ -101,7 +110,8 @@ interface FlagButtonProps {
101110 withCallingCodeButton ?: boolean
102111 withFlagButton ?: boolean
103112 containerButtonStyle ?: StyleProp < ViewStyle >
104- countryCode : CountryCode
113+ countryCode ?: CountryCode
114+ placeholder : string
105115 onOpen ?( ) : void
106116}
107117
@@ -114,6 +124,7 @@ export const FlagButton = ({
114124 countryCode,
115125 containerButtonStyle,
116126 onOpen,
127+ placeholder,
117128} : FlagButtonProps ) => {
118129 const { flagSizeButton : flagSize } = useTheme ( )
119130 return (
@@ -134,6 +145,7 @@ export const FlagButton = ({
134145 withCurrencyButton,
135146 withFlagButton,
136147 flagSize : flagSize ! ,
148+ placeholder,
137149 } }
138150 />
139151 </ View >
0 commit comments