VOOZH about

URL: https://thenewstack.io/learn-react-build-a-working-file-tree-and-manage-state/

⇱ Learn React: Build a Working File Tree and Manage State - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2022-06-04 05:00:16
Learn React: Build a Working File Tree and Manage State
tutorial,
Software Development

Learn React: Build a Working File Tree and Manage State

A React tutorial that shows you how to build a working file tree and and components.
Jun 4th, 2022 5:00am by Jessica Wachtel
👁 Featued image for: Learn React: Build a Working File Tree and Manage State
Welcome to the second part of our tutorial on learning React.js. Here’s a link to the GitHub Repo. The Read Me has all the instructions needed to get started plus some helpful links for anyone unfamiliar with GitHub. Seriously though, read the Read Me!

One of the features of React is its use of a virtual DOM. The virtual DOM is why React can update the web page’s Document Object Model (DOM) so quickly.

React takes two snapshots of the actual DOM. When a component is updated on the virtual DOM, it’s not yet updated on the DOM. The changes are compared with the second snapshot of the DOM, this one is a pre-virtual DOM update, allowing React to see where the updates were made and easily update the actual DOM. This process is much quicker than traversing the entire DOM. Here is an awesome YouTube video with more detail on this process.

The public/index.html (in the GitHub repo) is where this application connects to the DOM. The id “root” on line 11 in this file is where this happens. Root or app are very common names for this id but it can be named anything.

Under the Hood 

ReactDOM.Render is a react method that renders a React app to a webpage. ReactDOM.render takes two parameters, the element and the container. In src/index.js, you can see we are rendering the BasicApp element to the “root” container discussed in the previous section. This is a great article with more detail on ReactDOM.render.

index.html and index.js are standard in React applications. For a more detailed breakdown on the file structure of React applications and how they work together, this is an excellent article. This one dives deep into boiler plate files in the npx-create-react-app so some of it doesn’t apply here, but the general themes and concepts are the same.

An extension of JavaScript, JSX is essentially a JavaScript/ HTML combo and the building block for React. JSX allows you to code HTML and JavaScript in the same file and dramatically cuts down coding time. In our application, the text from BasicApp.js is shown in the browser. The “Welcome to This Tutorial” heading is simple text within h1 tags inside a React class component.Under the hood, Reacts library reads this as React.createElement(‘h1’, {}, “Welcome to This Tutorial”).

Check out this video which shows the side-by-side visual of JSX code and its vanilla HTML/ JavaScript counterpart. For more details about JSX under the hood, check out this article as well.

Before moving on, I suggest adding an HTML button to the page. You can see changes in the browser by saving the updated code file and refreshing the browser.

State and Components

A component is a basic building block of React. A UX is a set of components. (I chose class components for this first go around. Later on, I’m going to refactor this with functional components and hooks, but the older class components do a great job of illustrating the lifecycle methods and really help with drilling in React concepts before moving on.)

What Is State?

Simply put, state is a JavaScript object that holds the data you want to display on your site. In class components, state is set up with a constructor function. In our repo, the App.js file is where the state is located. Lines 6-8 and 10-11 in that component are standard in-class component state but what’s inside the state varies by application.

For our example, there is a simple array of tasks. As we move forward this will change to an empty object as we will be adding a deleting state dynamically through a text input box on the browser side.

Note the differences in the App.js vs. the BasicApp.js. The BasicApp.js is simple and doesn’t have any real functionality. The page was designed to introduce JSX and won’t be used moving forward.

How Components Work?

Check out line 17 in App.js. This page, though still simple, illustrates that flows one way — from parent to child.

In this instance, App.js is the parent and TaskComponent.js is the child. The way we pass state from parent to child is by naming it on the component and then putting it in curly braces to let React know to expect JavaScript and title it with the naming convention as you would with anything else. this.state is the name of the object and then tasks is the key and we are referencing the value. Take a look at the TaskComponent.js page and you can see how the specific elements are referenced.

In index.js, comment out the <BasicApp> and the BasicApp import and uncomment <App> and the App import and you can see

React’s unidirectional data flow is one of its main features. Here is a great article if you’d like to read more about it.

Next Steps

The basics are covered! You have a working file tree and components. What can you do over the next week to get more familiar with rendering React components to the DOM? How can you manipulate state? Can you map though an object or add another component?

Next week, we will add a text input box and manipulate state through the web page, add clickable functions, and learn about lifecycle methods.

TRENDING STORIES
Jessica Wachtel is a developer marketing writer at InfluxData where she creates content that helps make the world of time series data more understandable and accessible. Jessica has a background in software development and technical journalism.
Read more from Jessica Wachtel
SHARE THIS STORY
TRENDING STORIES
TNS owner Insight Partners is an investor in: Simply, Root.
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.