As someone who is self-taught, I know what it’s like to learn new technologies without direction or guidance. Looking back, I see my mistakes and distractions that delayed my progress. In this article, I will try to suggest the most optimal pathway for learning React.
Prerequisites for React
Let’s start with two fundamental languages that any web developer should know.
HTML elements are fundamental building blocks of any web application. You need a markup language like HTML to define structure and layout for the page. Coincidentally, templating language for React called JSX looks very similar to HTML. Most of the time, you will be using HTML elements to structure components in React.
With that being said, I believe that perfecting HTML comes down to practice and real world experience. So you don’t need to dwell on this technology until you master it. Instead, get a really good grip on HTML fundamentals and once you start to work and write code, you will understand the rest.
Learn most important elements, tags, and attributes in HTML. You will learn the rest by doing.
In general, CSS is a very confusing and difficult language to learn. Still, you can start with a strong foundation of basics and once again, expand on it as you gain web development experience in the real world.
I recommend that every web developer should know element, class, and ID selectors. Also understand document flow, box model, flexbox, and CSS grid.
It’s important to realize that even experienced developers use Google to learn about CSS properties. The key is to have general idea of how to approach a certain problem. You can figure out the details – CSS properties and their possible values – by searching it online.
Understanding functions is extremely important. Components in React are functions after all. You also need knowledge of functions to write event handlers and general helper functions for doing calculations. Knowledge of map() and filter() methods are also very necessary to do things like render multiple components in React.
Other newer features like object destructuring, spread and rest operators can bring simplicity to the code.
Git is an absolute necessity for building apps in React. All companies and development agencies use some type of version controls to successfully manage web development process.
Version control is not directly related to React or even web development. It’s still fairly easy and someone dedicated can learn Git in just few days. There are plenty of great video tutorials on Git. They also teach you how to upload your repositories to GitHub.
Foundations of React
Once you know all the prerequisites, it’s time to dip your toe into React. Before learning how to implement a certain feature, I recommend that developers should understand foundations of React, such as: components and their reusability, state and props, event handlers and JSX.
Since you’re already familiar with HTML, understanding JSX should not be too difficult for you. It’s an HTML-like language that allows you to declaratively invoke components and build a component tree to achieve the desired layout. JSX code is ultimately compiled into calls to React API. You can make these calls yourself, but the code becomes unreadable and difficult to follow. For this reason, almost all developers use JSX to structure and style applications in React.
Next, it will serve you well to understand the concept of components, and why their reusability is so important in React. Both types of components (class and function) have their own quirks and slightly different syntax. It may be worthwhile to understand both, but your company is probably going to use either one, not both. Still, understanding both types of components will help you see what’s happening in code snippets you find online.
State is also a foundational concept in React. It is tightly coupled to reactive and interactive features in React. It is integral to the concept of controlled inputs and implementing dynamic features that respond to users’ actions. State object is not a normal object in React, so it’s useful to learn how to approach it and get the best of state in React. State is also useful to implement dynamic rendering in response to user events. For example, render a component on click of a button in React.
Finally, props play an integral role as well. As previously mentioned, React web applications are essentially trees of components. Child components can have their own children, and so on. Props is the primary way for components to communicate with one another. React is fairly opinionated about props and has a strict guidelines for developers. For example, props can only be passed down from parents to children, not the other way round. A solid knowledge of props is necessary, even if larger web applications use Context API instead.
Useful React libraries
Knowing how to build basic components is great for learning and practice. If you’re building an MVP, or want fast development process, there are a lot of libraries with ready-to-use components. React community creates these useful custom components, which you can import and use in your own app. This can save you a lot of time.