02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Configuring our Project with Create-React-App

Getting Started with Create-React-App: A Beginner's Guide

Create-React-App is a powerful tool that allows developers to quickly set up a new React project with all the essentials already in place. Instead of spending hours configuring Webpack, Babel, and other tools, Create-React-App provides a boilerplate with a pre-configured environment, allowing developers to focus on writing their applications. In this video, we explore how to use Create-React-App and dive into the basics of setting up a modern React development environment. Below is an expanded guide on the topics covered.

What is Create-React-App and Why Use It?

Create-React-App (CRA) is an officially supported way to create single-page React applications with zero build configuration. When developers first start working with React, they often need to understand and configure various tools like Webpack, Babel, and ESLint. CRA abstracts away the setup process, providing a working development environment without worrying about those intricate configurations. This can be particularly useful for developers who are just starting their journey with React, as it removes barriers to getting started.

The command to start a new React project with Create-React-App is:

npx create-react-app my-app

This command installs all the dependencies, sets up a project directory structure, and initializes files, creating a solid foundation on which to build your app. As a result, developers save time and can begin coding immediately.

Benefits of Using Create-React-App

  • Quick Setup: Instead of spending hours setting up build configurations, CRA allows developers to spin up a project in minutes. This helps you focus on writing code rather than figuring out complex build tools.
  • Best Practices by Default: CRA ensures your project follows industry-standard best practices. It integrates tools like ESLint for linting and Jest for testing by default.
  • Optimized Development Workflow: CRA comes with Hot Module Replacement (HMR), allowing developers to see the changes they make in real time without needing a full refresh. This feature not only saves time but also ensures that application states remain intact during updates.

Project Structure and Configuration

After running Create-React-App, you will see a directory structure with folders like src and public. The src folder contains all the JavaScript files where you will write the core components of your application. The public folder includes the HTML template that renders your application. Some key files generated by CRA are:

  • index.html: This is the main HTML file that acts as the container for your React components.
  • index.js: The entry point of your React application, where components are rendered and attached to the DOM.
  • App.js: A simple default component created by CRA. This is the initial canvas for developers to build upon.

The CRA also creates a package.json file that holds metadata about the project, as well as information about installed dependencies and scripts. The react-scripts package is responsible for abstracting the build configurations, allowing developers to focus solely on writing application logic.

Hot Reloading and Fast Feedback Loop

One of the most powerful features of CRA is Hot Reloading. When changes are made to the JavaScript or CSS, they automatically appear in the browser without a refresh. This ensures developers are in a fast feedback loop, where they can see the effects of their modifications immediately, without losing the current state of the application.

This feature is made possible through webpack-dev-server, which is set up by CRA to automatically bundle and serve the project in development mode. The dev server watches for changes and injects the updated modules directly into the running application.

Managing Dependencies with npm or Yarn

When working with Create-React-App, managing dependencies is straightforward. CRA abstracts away many of the complexities of managing Webpack, Babel, and other dependencies by providing them under the react-scripts package. However, if you want to install additional libraries, such as Redux, React Router, or a UI library like Material-UI, you can do so using npm or yarn commands:

npm install redux react-redux

By doing so, you add these packages to your project’s node_modules, and they become available to use throughout your application.

Setting Expectations for Development Environment

To follow along with this course and use CRA effectively, there are a few prerequisites that should be in place:

  • Node.js: CRA requires Node.js, a JavaScript runtime that helps manage the dependencies in your project. At the time of recording, version 7.4 is recommended, but CRA supports newer versions as well.
  • npm: The Node Package Manager (npm) is required for managing project dependencies. Alternatively, you can use Yarn, which is also supported by CRA.

To verify that Node and npm are installed, use:

node -v
npm -v

These commands should output the installed versions, ensuring that your system is properly set up to begin developing with CRA.

Starting and Building a Project

After generating a project with Create-React-App, two important scripts are available for you:

  • npm start: Runs the project in development mode, opening it in your default browser at localhost:3000. Changes made to the project will automatically reflect in the browser.
  • npm run build: Compiles the project for production, creating optimized static files for deployment. The output files are saved to the build folder, which can be served on any web server.

Building Your First React Component

Once you have your environment set up with Create-React-App, the next step is to start building components. In React, components are the building blocks of an application. The video dives into creating a simple App component that renders a "Hello World" message to the DOM. As you build your first React component, you start understanding the basics of component-based architecture, the way data flows in React, and how you can split your application into smaller, reusable pieces.

Understanding Reducers in Redux

The course also touches on the basics of Redux, particularly focusing on reducers. Redux is a predictable state container for JavaScript applications and is commonly used with React to manage the application's state. A reducer in Redux is a pure function that takes the current state and an action as arguments and returns a new state.

For new developers, understanding how reducers work is key to grasping the data flow in Redux. In this context, Create-React-App acts as a starting point, providing a stable environment in which to implement state management through Redux.

Creating a Seamless Development Experience

A major takeaway for new developers starting with CRA is its focus on simplicity and best practices. The video highlights the importance of focusing on writing quality code instead of dealing with mundane configurations. With CRA, developers are empowered to:

  • Experiment Quickly: Developers can create multiple projects with CRA to experiment with different features, libraries, and configurations, providing a low-risk environment to learn.
  • Learn Modern JavaScript: CRA supports the latest JavaScript features (ES6/ES7), which means developers also get a chance to learn and work with the most modern syntax. This includes features like arrow functions, destructuring, and async/await.

Final Thoughts

Create-React-App is an excellent starting point for anyone looking to learn React and start building applications without the friction of configuring build tools. It abstracts away the complex aspects of the environment setup, allowing developers to focus on learning the core concepts of React, experimenting with different tools, and building effective user interfaces. As you continue through the course, you will also learn how to integrate Redux for state management, giving your applications a predictable state flow and scalability.

Whether you are new to React or already have some experience, Create-React-App is a powerful ally in your developer journey. The ability to quickly create new projects, experiment with features, and work with the latest JavaScript tools makes CRA invaluable in accelerating learning and productivity.


If you're ready to continue, let's start building your first components and integrating state management, making your applications dynamic and responsive.

Happy coding!

Video Transcript

00:01Welcome to Mastering Redux.
00:03My name is Ben Fowler
00:04and this is a packed publishing production.
00:07So who this title? Well, who should be watching this title?
00:11Uh, you should be a React developer,
00:13although if you're not a full on React developer
00:15but have a little bit of familiarity with it,
00:17then you're already in a good place.
00:19You definitely have to know JavaScript.
00:21And with that, we're gonna cover a lot
00:23of new ES six features in this title,
00:25but we're not gonna dig too deep into how they work.
00:27We're just gonna show you how to work with them.
00:30So with that said, what is going to be inside of this title?
00:33This title is split into four chapters
00:35where our first chapter will be about understanding
00:38how reducers work and what they actually are.
00:41And then we're gonna be rendering in the second chapter,
00:45we're gonna be rendering Redux data within React,
00:48and then we're gonna make our React application a lot more
00:51dynamic with more content from Redux.
00:54And last but not least,
00:55we're gonna integrate the React Redux Library into our
00:59application itself.
01:00So let's get started with chapter one.
01:02And chapter one is about getting started with reducers,
01:04where we're gonna be setting up our environment,
01:07create our React components, work
01:09with the React State itself, create our first reducer,
01:12understand what that is, and also test things out with Jes.
01:16Integrate everything with Redux. And there you go.
01:18We have a lot of stuff to cover in chapter one.
01:21So let's jump right into setting up our environment
01:23where we're gonna be actually show you how
01:26and where our starting point is.
01:29Uh, we're gonna be using Hot Reloading, we react Jes
01:32and a server, and it's all gonna be bundled up together
01:34using the Create React app.
01:36So let's jump right into it.
01:38Welcome. So let's get started.
01:40And the first thing is we have to set expectations.
01:44And for one, you wanna make sure
01:45that you have Node installed
01:47and you wanna be in a very UpToDate version.
01:49The current version that I'm running on is 7.4.
01:52Make sure that you also have NPM running or installed
01:57and a UpToDate version of that as well.
01:59You'll find more information about how to update
02:01and how to install Note
02:03and NPM if you don't have
02:04that installed already in the links
02:07provided with this chapter's documentation.
02:10With that said, I'm gonna assume that you have Node
02:12and you have NPM.
02:14And what I'm gonna do is I'm gonna show you how we're going
02:16to basically start our project up.
02:19We're gonna take a boil plate version of our application
02:23and we're gonna leverage something
02:24that's called Create React app.
02:26Now, create React app is a really, really wonderful tool
02:30that basically what it does is makes our application run,
02:35um, and start up with all the basic boil plates
02:38that you need to, you'll find more information again in the
02:41links provided, but I'm gonna go ahead
02:43and first just literally install that into our system.
02:48So I'm gonna go ahead and I'm gonna install it into NPM
02:51install into the Global Sphere,
02:53and I'm gonna create React app.
02:56That's a, that's the tool that we're going to be installing,
03:00um, the packaged more accurately.
03:02And I'm gonna go ahead and it's gonna go through
03:04that process and globally install our Create React app.
03:08Now that we have that, I'm gonna go ahead
03:10and choose the folder in which I want
03:13to actually create our project.
03:14And I'm gonna go ahead and install
03:17after we've had it installed more accu accurately.
03:21I'm gonna call create React app as a global command
03:26because we installed it.
03:27Again, a reminder, we installed it in the global space.
03:30So now we'll have access to it.
03:32And I'm gonna go ahead and define the name of our project
03:35and I'm gonna call this reduc course.
03:41So our reduc course, I'm gonna go ahead and enter,
03:44and once I do that, it's gonna go through the process
03:47of actually installing a lot of dependencies
03:50and building up a starter project for us.
03:53It's gonna take a bit of a while
03:54because it's actually going to load up
03:56and install quite a lot of different libraries, making sure
03:59that we don't, just don't have to, whatever is the basics,
04:02whatever is the starting point, we just don't have
04:04to worry about at all.
04:07With that said, I'm just gonna let this complete
04:09and once this installation is done,
04:11we're gonna have a basic starter project with React,
04:14with hot reloading, with a live server, with Babel, with um,
04:19um, JSX, which with ES six
04:22and a lot of other features that were added in.
04:24And you could see that now that we're basically done,
04:26you'll see the how much things were installed.
04:28Quite a lot of things.
04:30Now the nice thing about this is once we're done
04:32with this installation, and I'm just gonna go ahead
04:35and literally go into our folder.
04:37So I'm gonna go into Redux Cores and I'm gonna go ahead
04:40and call Sublime and open up that folder.
04:43So we could take a peek at the folder structure
04:45that we've just created.
04:47And if I just push this into our screen, we'll see
04:50that automatically a lot of libraries were added in.
04:54It created a public folder for us with A-H-T-M-L,
04:58it created some source files for us,
05:00and it even created our package.
05:02Do JSON. Now notice how most
05:04of the dependencies are hidden away from our view,
05:07and those are dependent on React scripts.
05:10While our React
05:12and React DOMA are those dependencies,
05:14the only technical dependencies that we have
05:16for our project directly.
05:18While these are all in dev dependencies, all the rest.
05:22With that said, let's go ahead
05:23and show you how do you actually get this project started.
05:26And that is really easy.
05:27All you have to do is type NPM start
05:30whenever you wanna start it.
05:31And whenever you want to bundle up your files into static
05:34files for production,
05:35then you would write NPM Run build from within
05:38your application.
05:40So in our case, I'm gonna type your NPM start
05:42and literally is gonna go through the process
05:44of starting up our server.
05:47And once our server is started up, you'll see
05:49that now it's gonna actually open up our server.
05:52Welcome to React js,
05:54and if I just go ahead into our source files here
05:57and go into my source,
05:59go into my app, you'll already see that.
06:01There we go. This is the app that was created.
06:03Our server is running. Not only that, if I go ahead here
06:06and welcome to React and, uh, type your 2.0 and save it.
06:10If I literally just go back into my browser, you'll see
06:13that now it automatically refreshed.
06:15I don't have to click on refresh, I'm automatically started
06:18and I already have something going on in my application.
06:22So that's gonna be our starting point.
06:24And you could download our source files from the GI
06:28repository that you could find in the links as
06:31provided into this project as well,
06:32or from wherever you downloaded the files,
06:35or start off from scratch, literally to gather with us with
06:38what we've just done right now.
06:40Um, see you in the next lecture.
06:42When we continue in this lecture,
06:45we set up our production,
06:47our development environment more accurately with the help
06:50of create React app In the next lecture,
06:53we're gonna continue down our path
06:55as we create our first React component.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!