Skip to content

Commit 11c7579

Browse files
lunaleapsLuna Wei
authored and
Luna Wei
committed
Add a brief summary to top level index
1 parent 5ab4348 commit 11c7579

File tree

6 files changed

+31
-5
lines changed

6 files changed

+31
-5
lines changed
Loading
Loading
Loading
Loading

src/content/learn/describing-the-ui.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ React is a JavaScript library for rendering user interfaces (UI). UI is built fr
1818
* [How to conditionally render components](/learn/conditional-rendering)
1919
* [How to render multiple components at a time](/learn/rendering-lists)
2020
* [How to avoid confusing bugs by keeping components pure](/learn/keeping-components-pure)
21+
* [Why understanding your UI as trees is useful](/learn/understanding-your-ui-as-a-tree)
2122

2223
</YouWillLearn>
2324

@@ -523,6 +524,29 @@ Read **[Keeping Components Pure](/learn/keeping-components-pure)** to learn how
523524

524525
</LearnMore>
525526

527+
## Your UI as a tree {/*your-ui-as-a-tree*/}
528+
529+
React uses trees to model the relationships between components and modules.
530+
531+
A React render tree is a representation of the parent and child relationship between components.
532+
533+
<Diagram name="generic_render_tree" height={250} width={500} alt="A tree graph with five nodes, with each node representing a component. The root node is located at the top the tree graph and is labelled 'Root Component'. It has two arrows extending down to two nodes labelled 'Component A' and 'Component C'. Each of the arrows is labelled with 'renders'. 'Component A' has a single 'renders' arrow to a node labelled 'Component B'. 'Component C' has a single 'renders' arrow to a node labelled 'Component D'.">An example React render tree.</Diagram>
534+
535+
Components near the top of the tree, near the root component, are considered top-level components. Components with no child components are leaf components. This categorization of components is useful for understanding data flow and rendering performance.
536+
537+
Modelling the relationship between JavaScript modules is another useful way to understand your app. We refer to it as a module dependency tree.
538+
539+
<Diagram name="generic_dependency_tree" height={250} width={500} alt="A tree graph with five nodes. Each node represents a JavaScript module. The top-most node is labelled 'RootModule.js'. It has three arrows extending to the nodes: 'ModuleA.js', 'ModuleB.js', and 'ModuleC.js'. Each arrow is labelled as 'imports'. 'ModuleC.js' node has a single 'imports' arrow that points to a node labelled 'ModuleD.js'.">An example module dependency tree.</Diagram>
540+
541+
A dependency tree is often used by build tools to bundle all the relevant JavaScript code for the client to download and render. A large bundle size regresses user experience for React apps. Understanding the module dependency tree is helpful to debug such issues.
542+
543+
<LearnMore path="/learn/understanding-your-ui-as-a-tree">
544+
545+
Read **[Your UI as a Tree](/learn/understanding-your-ui-as-a-tree)** to learn how to create a render and module dependency trees for a React app and how they're useful mental models for improving user experience and performance.
546+
547+
</LearnMore>
548+
549+
526550
## What's next? {/*whats-next*/}
527551

528552
Head over to [Your First Component](/learn/your-first-component) to start reading this chapter page by page!

src/content/learn/understanding-your-ui-as-a-tree.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ The root node in a React render tree is the [root component](/learn/importing-an
136136

137137
You'll notice in the above render tree, there is no mention of the HTML tags that each component renders. This is because the render tree is only composed of React [components](learn/your-first-component#components-ui-building-blocks).
138138

139-
React, as a UI framework, is platform agnostic. On react.dev, we showcase examples that render to the web, which uses HTML markup as its UI primitives. But a React app could just as likely render to a mobile or desktop platform, which may use different UI primitives like [UIView](https://developer.apple.com/documentation/uikit/uiview) or [Framework Element](https://learn.microsoft.com/en-us/dotnet/api/system.windows.frameworkelement?view=windowsdesktop-7.0).
139+
React, as a UI framework, is platform agonistic. On react.dev, we showcase examples that render to the web, which uses HTML markup as its UI primitives. But a React app could just as likely render to a mobile or desktop platform, which may use different UI primitives like [UIView](https://developer.apple.com/documentation/uikit/uiview) or [FrameworkElement](https://learn.microsoft.com/en-us/dotnet/api/system.windows.frameworkelement?view=windowsdesktop-7.0).
140140

141141
These platform UI primitives are not a part of React. React render trees can provide insight to our React app regardless of what platform your app renders to.
142142

@@ -252,11 +252,13 @@ With conditional rendering, across different renders, the render tree may render
252252

253253
In this example, depending on what `inspiration.type` is, we may render `<FancyText>` or `<Color>`. The render tree may be different for each render pass.
254254

255-
Although render trees may differ across render pases, these trees are generally helpful for identifying what the top-level and leaf components are in a React app. Top-level components are the components nearest to the root component and affect the rendering performance of all the components beneath them and often contain the most complexity. Leaf components are near the bottom of the tree and have no child components and are often frequently re-rendered. Identifying these categories of components are useful for understanding data flow and performance of your app.
255+
Although render trees may differ across render pases, these trees are generally helpful for identifying what the top-level and leaf components are in a React app. Top-level components are the components nearest to the root component and affect the rendering performance of all the components beneath them and often contain the most complexity. Leaf components are near the bottom of the tree and have no child components and are often frequently re-rendered.
256+
257+
Identifying these categories of components are useful for understanding data flow and performance of your app.
256258

257259
## The Module Dependency Tree {/*the-module-dependency-tree*/}
258260

259-
Another relationship in a React app that can be modeled with a tree are an app's module dependencies. As we [break up our components](/learn/importing-and-exporting-components#exporting-and-importing-a-component) and logic into separate files, we create [JS modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) where we may export components, functions or constants.
261+
Another relationship in a React app that can be modeled with a tree are an app's module dependencies. As we [break up our components](/learn/importing-and-exporting-components#exporting-and-importing-a-component) and logic into separate files, we create [JS modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) where we may export components, functions, or constants.
260262

261263
Each node in a module dependency tree is a module and each branch represents an `import` statement in that module.
262264

@@ -272,9 +274,9 @@ The root node of the tree is the root module, also known as the entrypoint file.
272274

273275
Comparing to the render tree of the same app, there are similar structures but some notable differences:
274276

275-
* The nodes that make-up the tree represent modules, versus components.
277+
* The nodes that make-up the tree represent modules, not components.
276278
* Non-component modules, like `inspirations.js`, are also represented in this tree. The render tree only encapsulates components.
277-
* `Copyright.js` appears under `App.js` but in the render tree, `Copyright`, the component, appears as a child of `InspirationGenerator`. This is because `InspirationGenerator` accepts JSX as children props.
279+
* `Copyright.js` appears under `App.js` but in the render tree, `Copyright`, the component, appears as a child of `InspirationGenerator`. This is because `InspirationGenerator` accepts JSX as [children props](/learn/passing-props-to-a-component#passing-jsx-as-children), so it renders `Copyright` as a child component but does not import the module.
278280

279281
Dependency trees are useful to determine what modules are necessary to run your React app. When building a React app for production, there is typically a build step that will bundle all the necessary JavaScript to ship to the client. The tool responsible for this is called a [bundler](https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Understanding_client-side_tools/Overview#the_modern_tooling_ecosystem), and bundlers will use the dependency tree to determine what modules should be included.
280282

0 commit comments

Comments
 (0)