Skip to content

Latest commit

 

History

History
71 lines (49 loc) · 4.06 KB

react.md

File metadata and controls

71 lines (49 loc) · 4.06 KB

React`

React is useful for building dynamic, interactive user interfaces in web applications. It allows for the creation of reusable UI components and efficiently updates and renders components when data changes.

https://react.dev/



Environment Variables

  • .env will be used for the application and build configuration; if it is not there .env.default will be used
  • We use esbuild's define configuration to set environment variables in the application:
    • https://esbuild.github.io/api/#define
    • process.env.NODE_ENV is set to "development" if the node build.js --dev flag is set; and production otherwise
    • Any environment variable that starts with REACT_APP_ will be set - this is for configuring the front-end; ex: changing an API hostname

<StrictMode>

If process.env.NODE_ENV is "development" then React's StrictMode will be enabled in src/index.tsx - this enables additional debug tooling that helps find bugs during development.

https://react.dev/reference/react/StrictMode


React App Anatomy

Static index.html render target + included bundles

The HTML file that you visit from the browser is in (assets/index.html)[../assets/index.html]. It gets copied over to the dist directory during the esbuild build.

Parts:

  • <link rel="stylesheet" href="global.css"> - global CSS asset (not built, static)
  • <link rel="stylesheet" href="bundle.css"> - bundled CSS asset (built by build.js)
  • <div id="root"></div> - the application render target at id #root
  • <script src="bundle.js"></script> - the bunlded JS asset (built by build.js)
React app index.tsx entry point

(src/index.tsx)[../src/index.tsx] is the only entry point defined in build.js esbuild build option entryPoints as this application is a SPA pattern - entryPoints : [ './src/index.tsx' ].

  • Has multiple dev/prod configurations; if development:
  • Gets the root element and manages for React rendering:
    • createRoot( root_el ) - gets #root element and creates a root to display React components inside a DOM node
    • react_root.render( <App /> ) - renders main <App /> component to React root specified above
React app App.tsx main application

(src/App.tsx)[../src/App.tsx] is the main React app entry point. It pulls in the main components of the application and is meant to be simple to understand as it's a starting point for the application's component tree.