liveBook · Manning

JSX

As explained in D3.js in Action, Third Edition

JSX is a JavaScript syntax extension for expressing user-interface markup within JavaScript code.

JSX is a JavaScript syntax extension for expressing component markup directly inside JavaScript. React functional components return JSX, including elements, expressions, and conditional content. section 8.3

Use JSX to connect component state and data with visible interface output:

  • Render a loading message while a loading state is true. section 8.3
  • Render a Charts component after loading finishes. section 8.3
  • Pass fetched data into a component through props. section 8.3
Listing 8.1 Initial state of App.js
import { useState } from 'react';                                 #1
import * as d3 from 'd3';                                        
import Charts from './Charts/Charts';                           

const App = () => {
  const [loading, setLoading] = useState(true);               #2

  return (
    <div className="container">                                   
      {loading && <div className="loading">                        #3
        Loading...</div>}                                      
      {!loading && <Charts />}                                  
    </div>
  );
};

export default App;

Inspect the compact App.js example to see JSX conditions switch between loading feedback and the chart dashboard. section 8.3

How D3.js in Action, Third Edition covers it

How deep it goes
Defines functional-component returns, conditional expressions, and props, but does not explain JSX implementation internals.
Examples
Demonstrates App.js rendering Loading... conditionally, then rendering Charts with fetched data.
What it assumes
Assumes basic JavaScript functions while introducing React functional components and their JSX returns.
What you can do after
Build it from scratch by writing a React component that conditionally renders interface elements and passes data through props.
How it connects
Connects JavaScript, React functional components, props, state, conditional rendering, and data loading.

Also explained in

Compare how 6 books explain JSX →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of D3.js in Action, Third Edition. The section links point to the parts of the book it draws on.