JSX

Embedding JS in JSX

Use curly braces {} to embed JS expressions:

const name ="Hen"
const element =<h1>Hello, {name}!</h1>

const a =5
const b =10
const element =<p>{a} + {b} = {a + b}</p>

Nesting the JSX

function App() {
  return (
    <div>
      <h1>My App</h1>
      <Welcome name="Hen" />
      <p>JSX is awesome!</p>
    </div>
  )
}

React Fragment

  1. Using <React.Fragment>:
import React from 'react'

function App() {
  return (
    <React.Fragment>
      <h1>Title</h1>
      <p>Some text</p>
    </React.Fragment>
  )
}

export default App
  1. Using shorthand <>:
function App() {
  return (
    <>
      <h1>Title</h1>
      <p>Some text</p>
    </>
  )
}