haosmark
haosmark

Reputation: 1127

native-base dynamically set button property?

I'm looking for a way to dynamically add bordered property to the button element, how can I do that?

So I need to switch from <Button> to <Button bordered>. Any way to do this without assigning an entire <Button><Text>I'm a button</Text></Button> to a variable, then duplicating the same but with bordered?

Upvotes: 0

Views: 443

Answers (1)

Ravi
Ravi

Reputation: 35569

You can use true or false based on your selection. Store its value in state and when you do some operation set it to true. This is how your Button will look.

<Button bordered={this.state.isBordered}><Text>I'm a button</Text></Button>

whenever you want to change its value just use setState and it's done

this.setState({
    isBordered:true
})

Update:

Combine it with transparent parameter and it will work

<Button transparent bordered={this.state.isBordered}><Text>I'm a button</Text></Button>

Upvotes: 1

Related Questions