User 965
User 965

Reputation: 189

React Native using variables in styles

I am using a styles file to handle everything relating to that within my application. I am trying to set a style based off of a variable that is previously declared however I am unsure of the syntax needed.

render() {
    const { params } = this.props.navigation.state;
    return (
        <View style={styles.${params.key}}>

        </View>
    );
}

The line in question is the style={styles.${params.key}} but that line is not properly compiling. Not sure on the correct syntax of this. Thanks.

Upvotes: 0

Views: 1605

Answers (1)

Aleksandr Medvedev
Aleksandr Medvedev

Reputation: 8958

I think it's going to be something like that:

styles[params.key]

Upvotes: 3

Related Questions