liveBook · Manning

Component

As explained in Build Financial Software with Generative AI (From Scratch)

A user interface component is a reusable software unit that encapsulates part of an application's visual structure and interaction behavior.

A component is a reusable, self-contained piece of code that renders part of a user interface. In React, components are the building blocks of a page. State holds information that can change a component’s behavior and trigger rendering; hooks help manage that state and the component’s lifecycle. section 6.1

A practical boundary is to let a page retrieve data and pass it to components that present it. An audit-log page, for example, can supply records to a component that displays them and handles opening record details. This keeps presentation code in smaller, more manageable pieces. It is a useful pattern, not an absolute rule: when data is needed by only one component, that component may make its own API call. section 9.5.2 section 10.5.2

Extracting shared navigation

A dashboard initially contains both a top bar and a sidebar. Move each into its own component, then render both on the dashboard and other pages. Pass the drawer’s open state and toggle function to each. If every page must repeat that state and function, consider wrapping the two navigation pieces in one component instead. section 6.3

A focused display component

A company listing receives company data from its page and renders a clickable grid. Its image component checks that a logo has the expected base64 image format before displaying it. A dedicated component can make display rules consistent wherever it is reused, though an overly specific one may be worth generalizing. section 10.2.4

Listing 10.18 Base64 image
const isBase64Image = (base64: string) => {  #1
    const regex = /^data:image\/[a-zA-Z]+;base64,/;  #1
    if (!regex.test(base64)) {  #1
        return '';  #1
    } else {  #1
        return base64;  #1
    }  #1
}  #1
 #1
export default function ImageBase64({base64, #2
      alt = 'Image',  width = '100%',  maxWidth = '100px'}:  #3
➥ Readonly<ImageProps>) {  #3

    const imageSource = isBase64Image(base64); #3

    return (
        <Box  #4
            component="img"  #4
            src={imageSource}  #4
            alt={alt}  #4
            sx={{  #4
                width: width,  #4
                maxWidth: maxWidth,  #4
            }}  #4
        />  #4
    ); #4
} #4

Inspect how a small component combines image validation, display properties, and a Material UI element behind one reusable interface. section 10.2.4

Component boundaries can evolve with user needs. An exception page can become a component so file screens can display the relevant exceptions; a batch screen can gain a statistics component. Further ahead, dashboards could offer movable prepackaged components, user-configured fields and charts, or components written against an API. Those are possible extensions, not requirements for an initial dashboard. section 8.8 section 12.3.2

How Build Financial Software with Generative AI (From Scratch) covers it

How deep it goes
Defines components and works through extraction, data passing, local state, and fetching-boundary decisions; leaves customizable dashboard components as possibilities.
Examples
Uses extracted dashboard navigation, audit-record presentation, a company grid with validated images, and a recent-batches grid.
What it assumes
Assumes basic familiarity with HTML, CSS, and the DOM for React, while defining components, state, and hooks at an introductory level.
What you can do after
Build it from scratch by extracting repeated UI, passing page data into presentation components, and choosing where component-specific fetching belongs.
How it connects
Connects components to React state, hooks, pages, API calls, and Material UI DataGrid.

Also explained in

Compare how 11 books explain component →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Financial Software with Generative AI (From Scratch). The section links point to the parts of the book it draws on.