JSX

Need to import react to use

  • Combines logic with display

  • Can put any js expression within braces in JSX

  • React elements are immutable js objects

  • its elements are just JavaScript objects, you could potentially look at and clone with changes

  • const name = 'Josh Perez';
    const element = <h1>Hello, {name}</h1>;
    
    const element = <img src={user.avatarUrl} />;
    //either use quote string or js expression

    auto esapes values in JSX to prevent XSS

Syntax

  • Can close empty tags with /> i.e <img src=... />

  • Camel case:

    • class => className

    • tabindex => tabIndex

  • Can have nested divs, but must have a single outermost div or fragments

  • Can be multiple lines

JSX transform

Rendering with Variable

Inline Logic

Prevent Component from Rendering

just return null

Fragments

Last updated