Pablo Duranti Pablo Duranti - 3 months ago 15
React JSX Question

JSX- How can I manipulate strings in JSX?

I have a string in a JSX file that I have to manipulate this way:

Let's suppose I have the following string with this value

medical_specialty = "Plastic Surgery"


I need to do this:

medical_specialty.replace(' ', '-').toLowerCase()


to transform it to
plastic-surgery


Do I have full JavaScript syntax in JSX files?

Answer

You can use this sysntax in JSX files.
For example, using react:

  render() {
    let medical_specialty = "Plastic Surgery"

    medical_specialty = medical_specialty.replace(' ', '-').toLowerCase()

    return (
        <div>
            { medical_specialty }
        </div>
    )
  }

As Dave Newton said, JSX is nothing more than a reprocessor step that adds XML syntax to JavaScript.

Comments