1
{this.state.userFirst} //returns anime
{this.props.firstPlace} //returns netflix
{this.props.provider[0].netflixAnimeT //returns 495

My current Code is...

<p>
  {this.Capitalize(this.props.firstPlace)} has
  {`this.props.provider[0].${this.props.firstPlace}${this.Capitalize(
    this.state.userFirst || ""
  )}T`}
  {this.state.userFirst}
</p>;
Capitalize (str){
  return str.charAt(0).toUpperCase() + str.slice(1)
}

Currently outputs:

Netflix has this.props.provider[0].netflixAnimeT anime

However, I want output of:

Netflix has 495 anime

As I want it dynamic based on user ratings etc, how should I change my code in JSX? Thank you.

Emile Bergeron
  • 17,074
  • 5
  • 83
  • 129
YLO
  • 39
  • 7

1 Answers1

-1

Just replace

{`this.props.provider[0].${this.props.firstPlace}${this.Capitalize(
  this.state.userFirst || ""
)}T`}

with

{this.props.provider[0].${this.props.firstPlace}${this.Capitalize(
  this.state.userFirst || ""
)}T}

The backtick makes it a literal string. You can also do

`${var} literal`

EDIT I missed some nuances about it, but this should work:

{`${this.props.provider[0]}.${this.props.firstPlace}${this.Capitalize(
  this.state.userFirst || ""
)}T`}
Luan Nico
  • 5,376
  • 2
  • 30
  • 60