繁体   English   中英

如何使用 typescript 在本机反应中传递可重用组件的样式道具

[英]how to pass style props of a reusable component in react native using typescript

我想使用 typescript 在 react-native 中制作一个可重用的组件。 大多数时候,我将这种方式用作简单的 react-native 项目。 这次我想用 TypeScript 代替 JavaScript。 我该怎么做?

import React from 'react'
import { Text, StyleSheet, Platform } from 'react-native'
import { RFValue } from "react-native-responsive-fontsize";

const AppText = ({ children, style } ) => {
    return (
    <Text style={[styles.textcommon, style]} > {children} </Text>

    )
}

const styles = StyleSheet.create({
    textcommon: {
        fontSize: RFValue(18),
        alignSelf: 'center',
        color: '#fff',
        fontFamily: Platform.OS === 'android' ? 'Roboto-Light' : 'Avenir',
    }
})

export default AppText;

我会尝试:

const myChildWithPAssedStyle = ({ style, ...props}: {style: React.CSSProperties}) => {
 
}

如果您要求React.CSSProperties类型...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM