zavtra zavtra - 1 year ago 59
JSON Question

Interpolate JSON in React Component's attribute?

I have a React component whose value I would like to set via JSON in the attribute. However, I'd like concatenate a letter or word, but neither show up. Is there a proper way to concatenate strings inside of a Component's attribute? Here, I'm setting the

attribute of a TableView cell.

<Cell cellstyle="RightDetail" accessory="DisclosureIndicator"
detail={this.state.height} onPress={this.navHeight.bind(this)}/>

Which produces this:
(the value set for height).

I'd like to find a way to do something like:

detail="\{this.state.height} meters"

Is this possible to do in React/ES6?

Answer Source

You can use the backtick notation if you're in ES6,

detail={`${this.state.height} meters`}

Per here:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download