[英]How to get style props suggestions with react native typescript re-usable component?
I have a text re-usable component coded like this:我有一个编码如下的文本可重用组件:
import React, {FC, ReactNode} from 'react';
import {StyleSheet, Text as RNText} from 'react-native';
interface TextProps {
style?: any;
children: ReactNode | ReactNode[];
}
const Text: FC<TextProps> = ({style, children}) => {
return <RNText style={{...styles.text, ...style}}>{children}</RNText>;
};
export default Text;
const styles = StyleSheet.create({
text: {
color: colors.black,
fontFamily: fonts.light,
},
});
So every time I want to style it I don't get any prop suggestions for styling a react native text component:所以每次我想设置它的样式时,我都没有得到任何关于设置 React 本机文本组件样式的道具建议:
How can I get all react native styles props suggestions for a custom re-usable made component with typescript?如何使用 typescript 获取自定义可重用组件的所有 React Native styles 道具建议?
you should use StyleProp, look at the code below:你应该使用 StyleProp,看看下面的代码:
import {
ActivityIndicator,
StyleProp,
StyleSheet,
View,
ViewStyle,
TextStyle
} from 'react-native';
interface LazyLoadImageType {
imgUri: string;
onLoadEnd?: () => void;
style?: StyleProp<TextStyle>;
// or
style?: StyleProp<ViewStyle>;
// or
style?: StyleProp<ViewStyle | TextStyle>;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.