How to access properties of a custom component in React-Native.ts?

Asked

Viewed 23 times

0

In the React-Native.js you can simply access any property as follows:

const meuComponent = (props)=>{
    return(...);
}

Inside the component, you can access any property transferred to it, provided you put inside the tag:

<MeuComponente algumaProp="qualquer coisa" />

Therefore, with props.AlgumaProp can access what was passed by the component or screen that used.

I’d like to know how to do that in React-Native.ts, follows my code:

interface ButtonsProps extends TouchableOpacityProps{
    title: string;
    enabled: boolean;
} 

...

const styles = StyleSheet.create({
    container:{
        backgroundColor: props.enabled? colors.green: colors.heading,
        height:56,
        borderRadius:16,
        justifyContent:'center',
        alignItems:'center'
    } 

1 answer

0

  • This does not answer the question. It wants to access the prop in the stylesheet statement

  • Well observed I misunderstood the topic, but from what I saw you can use the stylesheet as a function and pass the props as parameter and use in styling https://stackoverflow.com/questions/42707327/passing-props-into-external-stylesheet-in-React-Native export const styles = (iconColor,iconSize) => StyleSheet.create({&#xA; icon : {&#xA; color: iconColor,&#xA; fontSize: iconSize&#xA; }&#xA;} @Rafaeltavares thanks for the remark.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.